Calculation for calendar days between 2 dates  [SOLVED]

Questions about MultiCharts and user contributed studies.
plaforte
Posts: 75
Joined: 16 Aug 2012
Has thanked: 17 times
Been thanked: 2 times

Calculation for calendar days between 2 dates

Postby plaforte » 06 Nov 2015

Hello, I use MC64 version 9.0 (build 10759)

I select a trendline on the chart and I want to calculate the span of time in calendar days of the trendline. This code works perfect when the 2 dates are in the same month but when the 2 dates are in 2 different months it outputs an uncorrect calculation. Is there any way to achieve what I want to do ?

value1=tl_getactive;
value2=tl_getbegindate(value1);
value3=tl_getenddate(value1);

value6=value3-value2; // Time calendar days

Thank you for your help
Pierre

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Calculation for calendar days between 2 dates

Postby TJ » 06 Nov 2015

Hello, I use MC64 version 9.0 (build 10759)

I select a trendline on the chart and I want to calculate the span of time in calendar days of the trendline. This code works perfect when the 2 dates are in the same month but when the 2 dates are in 2 different months it outputs an uncorrect calculation. Is there any way to achieve what I want to do ?

value1=tl_getactive;
value2=tl_getbegindate(value1);
value3=tl_getenddate(value1);

value6=value3-value2; // Time calendar days

Thank you for your help
Pierre
Look up these keywords:

TL_GetBegin_Dt
TL_GetEnd_Dt


ps. You have to convert all your TL to _dt suffix keywords to take advantage of this DateTime feature.


ps. see posts #1 & 2
[FAQ] How to Post Codes (... so that people can read)
viewtopic.php?f=16&t=11713

plaforte
Posts: 75
Joined: 16 Aug 2012
Has thanked: 17 times
Been thanked: 2 times

Re: Calculation for calendar days between 2 dates

Postby plaforte » 06 Nov 2015

Thank you very much you are a pro. I am confused about the date formats, I took the following code in the help section to display in the MessageLog the starting date and end date of the trendline. Now this parts indicate dates in 1903 and my chart is 2008 data. I understand that my formula is not the right one.

Code: Select all

VarTLstart=FormatDate("dd-MM-yyyy",ELDateToDateTime(value2));
VarTLend=FormatDate("dd-MM-yyyy",ELDateToDateTime(value3));

I would have a fix for that by keeping my old 2 dates format that I get with TL_GetBeginDate but I would like to know if there is an equivalent to the FormatDate function that I was using that would take the format like I had with my above code.

Thank you very much (I took a note about the code functionality in the message box)
Pierre

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Calculation for calendar days between 2 dates  [SOLVED]

Postby TJ » 06 Nov 2015

Thank you very much you are a pro. I am confused about the date formats, I took the following code in the help section to display in the MessageLog the starting date and end date of the trendline. Now this parts indicate dates in 1903 and my chart is 2008 data. I understand that my formula is not the right one.

Code: Select all

VarTLstart=FormatDate("dd-MM-yyyy",ELDateToDateTime(value2));
VarTLend=FormatDate("dd-MM-yyyy",ELDateToDateTime(value3));

I would have a fix for that by keeping my old 2 dates format that I get with TL_GetBeginDate but I would like to know if there is an equivalent to the FormatDate function that I was using that would take the format like I had with my above code.

Thank you very much (I took a note about the code functionality in the message box)
Pierre

You will have to convert the date to DateTime in order to calculate the number of days.


see post #12
Manipulating Dates and Times
viewtopic.php?f=16&t=6929

plaforte
Posts: 75
Joined: 16 Aug 2012
Has thanked: 17 times
Been thanked: 2 times

Re: Calculation for calendar days between 2 dates

Postby plaforte » 06 Nov 2015

Thank you very much, that solved my problem

Pierre


Return to “MultiCharts”