Time Difference

Hi,

I want to calculate the time difference between two fixed dates in calendar days or trading days.

My script with the fixed dates:

Start = BARDATE()>=STRDATE(DATE=2018-09-24) ;
End = BARDATE()<=STRDATE(DATE=2018-12-24) ;

How can I calculate the time difference between these two dates?

I appreciate any help and thank you very much.

Best wishes,
Thomas

Hi Thomas,

You need to use the VALUEWHEN() function to get the BarDate() values, and then subtract the Start value from the End to get the calendar days:

//Use BARDATE() for Calendar Days;
Start = VALUEWHEN(BARDATE(), BARDATE()==STRDATE(DATE=2018-09-24));
End = VALUEWHEN(BARDATE(), BARDATE()==STRDATE(DATE=2018-12-24));
End - Start

For trading days:

//Use BARINDEX() for Trading Days;
Start = VALUEWHEN(BARINDEX(), BARDATE()==STRDATE(DATE=2018-09-24));
End = VALUEWHEN(BARINDEX(), BARDATE()==STRDATE(DATE=2018-12-24));
End - Start

Capture