DateTimeGetString converts a datetime object to the string in a specified format.
string @DateTimeGetString(object dateTime, string format);
Parameters
object dateTime : Generated dateTime object
string format : The string format (empty string("") regards as "yyyy-MM-dd HH:mm:ss")
Return Value
Returns the DateTime object in the specified format.
Frequently used date format string
Standard format
| Format | Meaning | Example |
|---|---|---|
| mm-dd yyyy HH:mm:ss | Basic format | 03-18 2025 14:30:25 |
| MM-dd yyyy | Only date | 03-18 2025 |
| HH:mm:ss | Only time | 14:30:25 |
| mm/dd/yyyy | seperated by slash | 03/18/2025 |
| yyyyMMdd | unseperated date | 20250318 |
| yyyyMMddHHmmss | unseperated date and time | 20250318143025 |
Custom format
| Format | Meaning | Example |
|---|---|---|
| MM. dd yyyy years | Additional characters express (years) | 03-18 2025 years |
| MM. dd yyyy years HH hour mm minute ss seconds | Additional characters express | 03-18 2025 years 14 hour 30 minute 25 seconds |
| MM-dd yyyy (ddd) | Include weekday as abbreviated name | 03-18 2025 (Tue) |
| MM-dd yyyy (dddd) | Include weekday as full name | 03-18 2025 (Tuesday) |
Formats
| Format | Meaning | Example |
|---|---|---|
| yyyy | Year with century as a decimal number | 2025 |
| yy | Years without century as a zero-padded decimal number | 25 |
| MM | Month as a zero-padded decimal number | 03 |
| MMM | month as locale's abbreviated name | Mar. |
| MMMM | Month as locale's full name | March |
| dd | Day of the month as a zero-padded decimal number | 18 |
| ddd | Weekday as locale's abbreviated name | Tue |
| dddd | Weekday as locale's full name | Tuesday |
| HH | Hour (24-hour clock) as a zero-padded decimal number | 14 |
| hh | Hour (12-hour clock) as a zero-padded decimal number | 02 |
| mm | Minute as a zero-padded decimal number | 30 |
| ss | Second as a zero-padded decimal number | 25 |
| tt | Locale's equivalent of either AM or PM | PM |
Examples : Show the specified date string as message after getting and converting the current datetime object.
Example 1 (standard format)
t = @DateTimeNow();
buf =
@DateTimeGetString(t, ""); // buf =
@DateTimeGetString(t, "yyyy-MM-dd HH:mm:ss");
@Message(buf); // ex. 2025-03-18 14:30:25
Example 2 (express only time)
t = @DateTimeNow();
buf =
@DateTimeGetString(t, "HH:mm:ss");
@Message(buf); // ex. 14:30:25
Example 3 (express only date)
t = @DateTimeNow();
buf =
@DateTimeGetString(t, "yyyy-MM-dd");
@Message(buf); // ex. 2025-03-18
Example 4 (additional characters)
t = @DateTimeNow();
buf =
@DateTimeGetString(t, "MM. dd yyyy years HH hour mm minute ss seconds");
@Message(buf); // ex. 03-18 2025 years 14 hour 30 minute 25 seconds
Example 4 (generaly used in filename)
t = @DateTimeNow();
buf = @DateTimeGetString(t, "yyyyMMdd_HHmmss");
@Message(buf); // ex. 20250318_143025
Version Information
Supported Version: 10.3.25 or higher
Related Helps