FormatDateTime(Date: Date[, FormatString: String]): String
Date/time formatted as a string. If Date is Null, returns Null, otherwise returns Date formatted in accordance with String. If FormatString is omitted, the default windows date / time format will be used. See Max Basic Date and Time Formats for acceptable values of String.
FormatDateTime function syntax has these named arguments:
Parameter |
Description |
|---|---|
Date |
Required. Date to be converted. |
FormatString |
Optional. Format for the conversion. If not entered, uses the default date / time format. If "iso8601" is provided as the format string then the result will be an iso8601 formatted UTC date/time value. If "iso8601tz" is provided as the format string then the result will be an iso8601 formatted UTC date/time value with local timezone offset. |
Sample code:
Dim aDateTime as Date
aDateTime = Date + Time ' now
' format from DateTime variable
Dim isoDate as String, isoDateTz as String
isoDate = FormatDateTime(aDateTime, "iso8601")
isoDateTz = FormatDateTime(aDateTime, "iso8601tz")
Print "iso8601 DateTime:" & isoDate
Print "iso8601Tz DateTime:" & isoDateTz
' Convert to DateTime from string
Dim aTimeOnly as Date, aDateOnly as Date
aDateOnly = DateValue(isoDateTz)
aTimeOnly = TimeValue(isoDateTz)
Print "Parsed Date: " & aDateOnly
Print "Parsed Time: " & aTimeOnly