Function Formattime( "HHmmss", Time_s) that should be use to enable to preceiding "0", will not work because Time_S is a string and FormatTime is looking to format a time value as a number. That what I concluded.
Ah okay, now I see your reasoning.
Though your problem is solved, I just want to add that Time_s (and Time, CurrentTime_s, and Date, etc.) are numeric variables. For example,
Code: Select all
variables: myString1(""), myString2("");
if LastBarOnChart_s = True then begin
value1 = Time_s;
value2 = Time_s - 100;
// myString1 = Time_s; // gives a "types not compatible"-error
// myString2 = "Hello" - 100; // Same error here
Print("Time_s: ", Time_s, Spaces(3), "-5: ", (Time_s - 5), Spaces(3), "-500: ", (Time_s - 500));
end;
..will give an error if those two lines are not commented out. So, if you want to calculate with time, you can do that since it are numeric variables. For example:
Code: Select all
if LastBarOnChart_s = True then begin
value1 = CurrentTime_s;
// Substracting 1 minute from the current time
value2 = DateTime2ELTime_s(ELTimeToDateTime_s(value1) - ELTimeToDateTime(1));
value3 = value1 - 100;
Print(NewLine, "TimeNow: ", value1, Spaces(3), "With DateTime: ", value2, Spaces(3), "With Substracting from CurrentTime: ", value3);
Print(Spaces(3), "In more readable print: ", NumToStr(value1, 0), Spaces(3), NumToStr(value3, 0), NewLine,
Spaces(3), "Or even more creative: ", FormatTime("HH:mm [ss]", ElTimeToDateTime_s(value1)),
Spaces(3), FormatTime("hh:mm:ss tt", ElTimeToDateTime_s(value2)),
Spaces(3), FormatTime("h:s:s t", ELTimeToDateTime_s(value1)),
Spaces(3), FormatTime("ss:mm:HH", ELTimeToDateTime_s(value1)));
RecalcLastBarAfter(5);
end;
Which gives the following output..
Code: Select all
TimeNow: 173631.00 With DateTime: 173531.00 With Substracting from CurrentTime: 173531.00
In more readable print: 173631 173531
Or even more creative: 17:36 [31] 05:35:31 5:31:31 31:36:17
TimeNow: 173636.00 With DateTime: 173536.00 With Substracting from CurrentTime: 173536.00
In more readable print: 173636 173536
Or even more creative: 17:36 [36] 05:35:36 5:36:36 36:36:17
TimeNow: 173641.00 With DateTime: 173541.00 With Substracting from CurrentTime: 173541.00
In more readable print: 173641 173541
Or even more creative: 17:36 [41] 05:35:41 5:41:41 41:36:17
TimeNow: 173647.00 With DateTime: 173547.00 With Substracting from CurrentTime: 173547.00
In more readable print: 173647 173547
Or even more creative: 17:36 [47] 05:35:47 5:47:47 47:36:17
Just to show that practically anything can be done.
Edit: To give a more concrete example that actually can be useful, the function below (called "TimeNow") prints the time and date in a formatted string, so if I want to display the current time and date, that function can be used, which is more convenient than manually work with the time formats each time:
Code: Select all
TimeNow = Text(
FormatDate("dd-MM", ELDateToDateTime(CurrentDate)),
"_",
FormatTime("HH:mm:ss", ELTimeToDateTime_s(CurrentTime_s)),
Spaces(2));
For example:
Code: Select all
if LastBarOnChart_s = True then begin
Print(TimeNow);
RecalcLastBarAfter(5);
end;
Which looks like..
Code: Select all
02-12_17:51:05
02-12_17:51:10
02-12_17:51:15
02-12_17:51:20
02-12_17:51:25
02-12_17:51:30
02-12_17:51:35
Regards,
Josh