DateTimeToStr **requires** datetime, was: How to get a correct time string?

I am working on 15-minute timeframe,
and as you can see the screencut below,
the variable Time_string_2 = "";
and the variable Time_string_5= "00:00:00";
my full code as below:

// work on 15-minutes
dt = DateTime(); tn = TimeNum();
Date_string = DateTimeToStr(dt[0], 1);  // 1 = convert only date
Time_string_2 = DateTimeToStr(tn[0], 2); // 2 = convert only time
Time_string_5 = DateTimeToStr(tn[0], 5); // 5 = iso time only HH:MM:SS
printf("\nFirst date and time of this data: %s %s %s", Date_string, Time_string_2, Time_string_5 );

then I've tried to add
SetBarsRequired(sbrAll, sbrAll);
but it produces the same results.

Q1) How do I get the correct time string "19:45:00"?
Q2) Why DateTimeToStr(tn[0], 2) return an empty string?

Thank you very much :slightly_smiling_face:!

Your code is incorrect, DateTimeToStr accepts datetime format, not timenum. You are passing TimeNum and that is wrong:

Time_string_2 = DateTimeToStr(tn[0], 2); // wrong input
Time_string_5 = DateTimeToStr(tn[0], 5);  // wrong input

Should be:

Time_string_2 = DateTimeToStr( dt[0], 2 );// must pass datetime !
Time_string_5 = DateTimeToStr( dt[0], 5 );  // must pass datetime !
1 Like

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