Template Strings to Create Specific Output Timestamps
Template | Input String | Output TIMESTAMP | Notes |
---|---|---|---|
'yyyy-MM-dd hh:mm:ss'
|
'2009-09-16 03:15:24'
|
'2009-09-16 03:15:24'
|
|
'yyyy-mm'
|
'2011-02-08 07:23:19'
|
'2011-01-01 00:02:00'
|
The template above specifies only year first and minutes second, so the second element in the input string ("02") is used as minutes. Default values are used for Month and Day ("01") and for hours and seconds ("00"). |
'MMM dd, yyyy'
|
'March 7, 2010'
|
'2010-03-07 00:00:00'
|
MMM in the template above matches "March"; the template's 'comma space' matches the input string. If the template lacks the comma, so must the input string, or there is no output; If the input string lacks the comma, so must the template. |
'MMM dd,'
|
'March 7, 2010'
|
'1970-03-07 00:00:00'
|
Note that the template above doesn't use a year specifier, causing the output TIMESTAMP to use the earliest year in this epoch, 1970. |
'MMM dd,y'
|
'March 7, 2010'
|
'2010-03-07 00:00:00'
|
Using the template above, if the input string were 'March 7, 10', the output TIMESTAMP would be '0010-03-07 00:00:00'. |
'M-d'
|
'2-8'
|
'1970-02-08 00:00:00'
|
Absent a yyyy specifier in the template, as above, the earliest year in this epoch (1970) is used. An input string of '2–8−2011' would give the same result; using '2011–2−8' would give no result because 2011 is not a valid month. |
'MM-dd-yyyy'
|
'06-23-2011 10:11:12'
|
'2011-06-23 00:00:00'
|
Dashes as delimiters (as above) are fine, if template and input both use them in the same positions. Since the template omits hours, minutes, and seconds, zeroes are used in the output TIMESTAMP. |
|
|
|
You can have the specifiers in any order as long as that order matches the meaning of the input string you supply. The template and input string of the next example below have the same meaning (and the same output TIMESTAMP) as this example, but they specify months before days and seconds before hours. |
|
|
|
In the template used above, the order of the month and day specifiers is reversed from the example just above, and the specifier for seconds is before hours instead of after minutes; but because the input string also puts months before days and seconds before hours, the meaning (and the output TIMESTAMP) is the same as the example ABOVE. |
|
|
|
The template used above reverses (compared to the prior example above) the years and months specifiers, while the input string remains the same. In this case, the output TIMESTAMP uses the first element of the input string as the years, the second as the days, and the third as the months. |
|
|
|
With seconds omitted in the template, as above, the output TIMESTAMP uses 00 seconds. Any number of y specifiers produces the same result; but if the input string inadvertently uses a 1 instead of 11 for the year, as in '23-06-1 10:11:12', then the output TIMESTAMP becomes '0001-06-23 10:11:00'. |
|
|
|
Slashes as delimiters are fine, if template and input both use them in the same positions, as above. Using specifier hh, input times of 12:11:10 and 00:11:10 have the same meaning as a time in the morning. |
|
|
|
The input-string values However, changing the template gives useful output:
1 row selected
Note that for times after 12 noon (that is, for afternoon and evening times), the hours specifier must be HH instead of hh, and the input string must specify the afternoon or evening hour in 24-hour clock time, hours running from 00 to 23. Using specifier HH, input times of 12:11:10 and 00:11:10 have different meanings, the first as a time in the afternoon and the second as a time in the morning. Using the specifier hh, the times from 12:00 through 11:59:59 are morning times:
|