Rangefromdate gives unexpected date

This code

StartDate = Status("rangefromdate");
EndDate = Status("rangetodate");
Filter = Status("lastbarinrange");
AddColumn(StartDate, "StartDate", formatDateTime );
AddColumn(EndDate, "EndDate", formatDateTime );

produces this result
image

Quoting from Status():

"rangefromdate", "rangetodate" - return current auto-analysis From-To range as DateNums.

Quoting from DateTime():

Returns array of encoded date/time values suitable for using with AddColumn and formatDateTime constant to produce date time formated according to your system settings.

Same page also shows an example:

AddColumn( DateTime(), "Date / Time", formatDateTime );

From here we learn that formatDateTime takes in DateTime(), it even says so - formatDateTime. But as datenum() were passed in form of Status( "rangeFromDate" ) and Status( "rangeTodate" ):


Let us try using DateTimeConvert() before sending it to AddColumn():

startDate = DateTimeConvert( 2, Status( "rangeFromDate" ) );
endDate	  = DateTimeConvert( 2, Status( "rangeTodate" ) );

Filter = Status( "lastBarInRange" );
AddColumn( startDate, "Start Date", formatDateTime );
AddColumn( endDate, "End Date", formatDateTime );

which produces:
image

Excellent. Thank you. :slight_smile:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.