TimeToStr
Converts a time/date variable into a string. Use this function for calculating time differences or run times, and so on. Set Format to 6 to convert time periods that are in milliseconds, such as the times that are returned from the SysTime() and SysTimeDelta() functions.
Note: Once a date/time is retrieved as UTC, the string cannot be used by the Cicode functions StrToDate and StrToTime to synthesize a date/time value as these functions support local time only.
Time/date functions can only be used with dates from 1980 to 2035. You should check that the date you are using is valid with Cicode similar to the following:
IF StrToDate(Arg1)>0 THEN
...
ELSE
...
END
Syntax
TimeToStr(Time, Format [, UTC] )
Time:
The time/date variable.
Format:
Format of the string:
0 - Short time format, hh:mm AM/PM.
1 - Long time format, hh:mm:ss AM/PM.
2 - Short date format, dd/mm/yy.
3 - Long date format, day month year.
4 - Time and date, weekday month day year hh:mm:ss AM/PM.
5 - Long time period, hh:mm:ss. Time needs to be in seconds.
6 - Millisecond time period, hh:mm:ss.xxx ("xxx" represents milliseconds). Time needs to be in milliseconds.
7 - Short time period, hh:mm. Time needs to be in seconds.
8 - Long time period, "xxxxx Days hh Hours mm min ss sec where xxxxx = number of days since 1/1/1970". Time needs to be in seconds.
9 - Extended date format, dd/mm/yyyy.
UTC:
Universal Time Co-ordinate (optional)
0 - Display the string as a local date/time (default).
1 - Display the string as a UTC date/time (valid for formats 0-4 and 9).
Return Value
A string containing the converted time/date or period variable, or an empty string if invalid.
Related Functions
Example
! If the current system time is 11:50:00 a.m.
String=TimeToStr(TimeCurrent(),0);
! Sets String to "11:50 AM".
String=TimeToStr(125 + TimeCurrent(),5);
! Sets String to "11:52:05" (the current time + 2 minutes and 5 seconds).
See Also