Formating Time string

Questions about MultiCharts and user contributed studies.
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Formating Time string

Postby arjfca » 14 Sep 2011

I need to format a string that represent a time

To create the string i use

Code: Select all

TimeExitStr =text(Time));
If time is lower than 10 am, the result will be ( 9:45:12). There is a space before the 9

I want to format my string to be a "0" instead of the (space)

Result should be (09:45:12)

Any idea how I could achieved that?

Martin

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: Formating Time string

Postby SP » 14 Sep 2011

if time_S <100000 then
TimeExitStr = "0"+text(Time)) else TimeExitStr = text(Time));

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Formating Time string

Postby arjfca » 14 Sep 2011

Thanks

I just found the function FormatTime("hh:mm:ss", atime);

My time is (Time) that is the value of the ending time of a bar

The return string value for
FormatTime("hh:mm:ss", time) is "12:00:00" for every time (ending bar time) value

If i could have this function to work, it should resolve my problem

Martin

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Formating Time string

Postby JoshM » 15 Sep 2011

Thanks

I just found the function FormatTime("hh:mm:ss", atime);

My time is (Time) that is the value of the ending time of a bar

The return string value for
FormatTime("hh:mm:ss", time) is "12:00:00" for every time (ending bar time) value

If i could have this function to work, it should resolve my problem

Martin
I could not replicate your "12:00:00"-problem, but did had wrong values using your code (see below). To summarize, use EL_TimeToDateTime_s(Time_s) as input for the FormatTime() function.

Code: Select all

once cleardebug;

if CurrentBar > 500 and CurrentBar < 550 then begin

Print("Time of bar: ", time, NewLine,
Spaces(2), "With FormatTime(time): ", FormatTime("HH:mm:ss", time),
Spaces(2), "With FormatTime(time) with EL_TimeToTimeDate: ", FormatTime("HH:mm:ss", EL_TimeToDateTime(time)));
Print(Spaces(3), "With Time_s of bar: ", time_s, " formatTime: ", FormatTime("HH:mm:ss", ELTimeToDateTime_s(time_s)),
NewLine);
end;
And the output:

Code: Select all

Time of bar: 1004.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:04:00
With Time_s of bar: 100412.00 formatTime: 10:04:12

Time of bar: 1005.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:05:00
With Time_s of bar: 100537.00 formatTime: 10:05:37

Time of bar: 1006.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:06:00
With Time_s of bar: 100621.00 formatTime: 10:06:21

Time of bar: 1009.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:09:00
With Time_s of bar: 100917.00 formatTime: 10:09:17

Time of bar: 1012.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:12:00
With Time_s of bar: 101201.00 formatTime: 10:12:01

Time of bar: 1013.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:13:00
With Time_s of bar: 101346.00 formatTime: 10:13:46

Time of bar: 1016.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:16:00
With Time_s of bar: 101610.00 formatTime: 10:16:10

Time of bar: 1018.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:18:00
With Time_s of bar: 101830.00 formatTime: 10:18:30

Time of bar: 1020.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:20:00
With Time_s of bar: 102053.00 formatTime: 10:20:53

Time of bar: 1022.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:22:00
With Time_s of bar: 102231.00 formatTime: 10:22:31

Time of bar: 1023.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:23:00
With Time_s of bar: 102355.00 formatTime: 10:23:55

Time of bar: 1025.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:25:00
With Time_s of bar: 102525.00 formatTime: 10:25:25

Time of bar: 1025.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:25:00
With Time_s of bar: 102557.00 formatTime: 10:25:57

Time of bar: 1028.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:28:00
With Time_s of bar: 102810.00 formatTime: 10:28:10

Time of bar: 1034.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:34:00
With Time_s of bar: 103401.00 formatTime: 10:34:01

Time of bar: 1036.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:36:00
With Time_s of bar: 103633.00 formatTime: 10:36:33

Time of bar: 1038.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:38:00
With Time_s of bar: 103815.00 formatTime: 10:38:15

Time of bar: 1044.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:44:00
With Time_s of bar: 104435.00 formatTime: 10:44:35

Time of bar: 1044.00
With FormatTime(time): 00:00:00 With FormatTime(time) with EL_TimeToTimeDate: 10:44:00
With Time_s of bar: 104444.00 formatTime: 10:44:44
Regards,
Josh

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Formating Time string

Postby arjfca » 15 Sep 2011

Josh,
- I see, I see .... said the blind man.....

Thank you very much for the info. Well explain

Martin :)

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

Re: Formating Time string

Postby TJ » 15 Sep 2011

this might help to visualize the different time keywords:

Programmer's data box
http://www.traderslaboratory.com/forums ... a-box.html



48.32


Return to “MultiCharts”