StringToDTFormatted
Returns the DateTime value for the string in a particular format.
The format of the string expression, including the abbreviations and separators, is defined by the specified format string. The format string consists of one or more elements arranged in the desired order. Each element represents a particular part of the date in a specific format. Spaces and separator characters to be used can be inserted within the format string.
Usage
DateTime StringToDTFormatted("DateTimeString", "FormatString")
Parameters
- DateTimeString - time and date value in string format.
- FormatString - a format string, specifying the format of the output string expression representing the date and time
The following elements can be used in the format string:
- d Day of month as digits with no leading zero for single-digit days
- dd Day of month as digits with leading zero for single-digit days
- ddd Day of week as a three-letter abbreviation
- dddd Day of week as its full name
- M Month as digits with no leading zero for single-digit months
- MM Month as digits with leading zero for single-digit months
- MMM Month as a three-letter abbreviation
- MMMM Month as its full name
- y Year as last two digits, but with no leading zero for years less than 10
- yy Year as last two digits, but with leading zero for years less than 10
- yyyy Year represented by full four digits
- h Hours in 12-hour AM/PM format with no leading zero for single-digit hours
- hh Hours in 12-hour AM/PM format with leading zero for single-digit hours
- H Hours in 24-hour format with no leading zero for single-digit hours
- HH Hours in 24-hour format with leading zero for single-digit hours
- m Minutes with no leading zero for single-digit minutes
- mm Minutes with leading zero for single-digit minutes
- s Seconds with no leading zero for single-digit seconds
- ss Seconds with leading zero for single-digit seconds
- t One character AM/PM designator
- tt Multicharacter AM/PM designator
Return value
DateTime - a double-precision decimal DateTime value, corresponding to the first string parameter with a second string parameter format applied to it.
The integer portion of the DateTime value specifies the number of days since January 1st, 1900, and the fractional portion of the DateTime value specifies the fraction of the day since midnight.
Note
Attention! Check if the returned value is correct! If conversion fails, the function returns -1.
Example
StringToDTFormatted("22/11/2013 15:35", "dd/MM/yyy HH:mm")
will return 41600.649305555555 , which represents November 22nd 2013, 3:35 PM.
StringToDTFormatted("02/17/11", "MM/dd/yy")
will return 40591 , which represents February 17th 2011.
StringToDTFormatted("17/02/11", "MM/dd/yy")
will return -1, string conversion to DateTime format failed.
StringToDTFormatted("4:00 PM", "h:mm tt")
will return 2.666666666666667 , which represents the minimum value of JulianDate = January 1st 1900, 4:00 PM.