"d" | The day of the month, from 1 to 31. More information: the custom format specifier "d". | 2009-06-01T13:45:30 -> 1 2009-06-15T13:45:30 -> 15 |
"dd" | The day of the month, from 01 to 31. More information: the custom format specifier "dd". | 2009-06-01 -> 01T13:45:30 2009-06-15T13:45:30 -> 15 |
"ddd" | The abbreviated name of the day of the week. More information: the custom format specifier "ddd". | 2009-06-15T13: 45: 30 -> Mon 2009-06-15T13: 45: 30 -> Пн (ru-RU) 2009-06-15T13: 45: 30 -> lun. (fr-FR) |
"dddd" | The full name of the day of the week. More information: the custom format specifier "dddd". | 2009-06-15T13: 45: 30 -> Second (en-US) 2009-06-15T13: 45: 30 -> понедельник (ru-RU) 2009-06-15T13: 45: 30 -> lundi (fr-FR) |
"f" | The tenths of a second in a date and time value. More information: the custom format specifier "f". | 2009-06-15T13:45:30.6170000 -> 6 2009-06-15T13:45:30.05 -> 0 |
"ff" | The hundredths of a second in a date and time value. More information: the custom format specifier "ff". | 2009-06-15T13:45:30.6170000 -> 61 2009-06-00 -> 15T13:45:30.0050000 |
"fff" | The milliseconds in a date and time value. More information: the custom format specifier "fff". | 6/15/2009 13:45:30.617 -> 617 6/15/2009 13:45:30.0005 -> 000 |
"ffff" | The tenths of milliseconds in a date and time value. More information: the custom format specifier "ffff". | 2009-06-15T13:45:30.6175000 -> 6175 2009-06-0000 -> 15T13:45:30.0000500 |
"fffff" | The hundredths of milliseconds in a date and time value. More information: the custom format specifier "fffff". | 2009-06-15T13:45:30.6175400 -> 61754 6/15/2009 13:45:30.000005 -> 00000 |
"ffffff" | The millionths of a second in a date and time value. More information: the custom format specifier "ffffff". | 2009-06-15T13:45:30.6175420 -> 617542 2009-06-15T13:45:30.0000005 -> 000000 |
"fffffff" | The tenths of a millionths of a second in a date and time value. More information: the custom format specifier "fffffff". | 2009-06-15T13:45:30.6175425 -> 6175425 2009-06-15T13:45:30.0001150 -> 0001150 |
"F" | If nonzero, the tenths of a second in a date and time value. More information: custom format specifier "F". | 2009-06-15T13:45:30.6170000 -> 6 2009-06-15T13: 45: 30.0500000 -> (No Exit) |
"FF" | If nonzero, the hundredths of a second in a date and time value. More information: the custom format specifier "FF". | 2009-06-15T13:45:30.6170000 -> 61 2009-06-15T13: 45: 30.0050000 -> (No Exit) |
"FFF" | If nonzero, the milliseconds in a date and time value. More information: the custom format specifier "FFF". | 2009-06-15T13:45:30.6170000 -> 617 2009-06-15T13: 45: 30.0005000 -> (No Exit) |
"FFFF" | If nonzero, the tenths of milliseconds in a date and time value. More information: the custom format specifier "FFFF". | 2009-06-15T13:45:30.5275000 -> 5275 2009-06-15T13: 45: 30.0000500 -> (No Exit) |
"FFFFF" | If nonzero, the hundredths of milliseconds in a date and time value. More information: the custom format specifier "FFFFF". | 2009-06-15T13:45:30.6175400 -> 61754 2009-06-15T13: 45: 30.0000050 -> (No Exit) |
"FFFFFF" | If nonzero, the millionths of a second in a date and time value. More information: the custom format specifier "FFFFFF". | 2009-06-15T13:45:30.6175420 -> 617542 2009-06-15T13: 45: 30.0000005 -> (No Exit) |
"FFFFFFF" | If nonzero, the tenths of a millionths of a second in a date and time value. More information: the custom format specifier "FFFFFFF". | 2009-06-15T13:45:30.6175425 -> 6175425 2009-06-15T13:45:30.0001150 -> 000115 |
"g", "gg" | The period or era. More information: "g" or "gg" custom format specifier. | 2009-06-15T13:45:30.6170000 -> A.D. |
"H" | The time using a clock from 12 hours from 1 to 12. More information: the custom format specifier "h". | 2009-06-15T01:45:30 -> 1 2009-06-15T13:45:30 -> 1 |
"hh" | The time using a clock from 12 hours from 01 to 12. More information: the custom format specifier "hh". | 2009-06-01 -> 15T01:45:30 2009-06-01 -> 15T13:45:30 |
"H" | The time using a clock from 24 hours from 0 to 23. More information: custom format specifier "H". | 2009-06-15T01:45:30 -> 1 2009-06-13 -> 15T13:45:30 |
"Hh" | The time using a clock from 24 hours from 00 to 23. More information: the custom format specifier "HH". | 2009-06-01 -> 15T01:45:30 2009-06-13 -> 15T13:45:30 |
"K" | Time zone information. More information: the custom format specifier "K". | With Date Time values: 2009-06-15T13: 45: 30, what unspecified type -> 2009-06-15T13: 45: 30, Utc Type -> Z 2009-06-15T13: 45: 30, Type Local -> - 07: 00 (Depends on Local Computer Settings) With DateTimeOffset values: 2009-06-15T01:45:30-07:00--> -07:00 2009-06-15T08:45:30 + 00:00--> + 00:00 |
"m" | The minute, from 0 to 59. More information: the custom format specifier "m". | 2009-06-15T01:09:30 -> 9 2009-06-29 -> 15T13:29:30 |
"mm" | The minute, from 00 to 59. More information: the custom format specifier "mm". | 2009-06-15T01:09:30 -> 09 2009-06-45 -> 15T01:45:30 |
"M" | The month, from 1 to 12. More information: the custom format specifier "M". | 2009-06-15T13:45:30 -> 6 |
"MM" | The month, from 01 to 12. More information: the custom format specifier "MM". | 2009-06-06 -> 15T13:45:30 |
"MMM" | The abbreviated name of the month. More information: the custom format specifier "MMM". | 2009-06-15T13: 45: 30 -> Jun (en-US) 2009-06-15T13: 45: 30 -> Juin (fr-FR) 2009-06-15T13: 45: 30 -> Jun (zu-ZA) |
"MMMM" | The full name of the month. More information: the custom format specifier "MMMM". | 2009-06-15T13: 45: 30 -> June (en-US) 2009-06-15T13: 45: 30 -> Juni (da-DK) 2009-06-15T13: 45: 30 -> uJuni (zu-ZA) |
"s" | The second, from 0 to 59. More information: the custom format specifier "s". | 2009-06-15T13:45:09 -> 9 |
"ss" | The second, from 00 to 59. More information: the custom format specifier "ss". | 2009-06-15T13:45:09 -> 09 |
"t" | The first character of the AM / PM designator. More information: the custom format specifier "t". | 2009-06-15T13: 45: 30 -> P (en-US) 2009-06-15T13: 45: 30 -> 午 (ja-JP) 2009-06-15T13:45:30 -> (fr-FR) |
"tt" | The AM / PM designator. More information: the custom format specifier "tt". | 2009-06-15T13: 45: 30 -> PM (en-US) 2009-06-15T13: 45: 30 -> 午後 (ja-JP) 2009-06-15T13:45:30 -> (fr-FR) |
"y" | The year, from 0 to 99. More information: the custom format specifier "y". | 0001-01-01T00:00:00 -> 1 0900-01-01T00:00:00 -> 0 1900-01-01T00:00:00 -> 0 2009-06-15T13:45:30 -> 9 2019-06-19 -> 15T13:45:30 |
"AA" | The year, from 00 to 99. More information: the custom format specifier "yy". | 0001-01-01 -> 01T00:00:00 0900-01-00 -> 01T00:00:00 1900-01-00 -> 01T00:00:00 2019-06-19 -> 15T13:45:30 |
"yyy" | The year, with a minimum of three digits. More information: the custom format specifier "yyy". | 0001-01-01T00:00:00 -> 001 0900-01-01T00:00:00 -> 900 1900-01-1900 -> 01T00:00:00 2009-06-2009 -> 15T13:45:30 |
"yyyy" | The year as a four digit number. More information: the custom format specifier "yyyy". | 0001-01-01T00:00:00 -> 0001 0900-01-01T00:00:00 -> 0900 1900-01-1900 -> 01T00:00:00 2009-06-2009 -> 15T13:45:30 |
"yyyyy" | The year as a five digit number. More information: the custom format specifier "yyyyy". | 0001-01-01T00:00:00 -> 00001 2009-06-15T13:45:30 -> 02009 |
"z" | UTC time difference, no leading zeros. More information: the custom format specifier "z". | 2009-06-15T13:45:30-07:00 -> -7 |
"zz" | UTC time difference, with a leading zero of a single digit value. More information: the custom format specifier "zz". | 2009-06-15T13:45:30-07:00->-07 |
"zzz" | Hours and minutes UTC offset. More information: the custom format specifier "zzz". | 2009-06-15T13:45:30-07:00->-07:00 |
"" | The time separator. More information: the ":" custom format specifier. | 2009-06--> 15T13:45:30: (en-US) 2009-06--> 15T13:45:30. (it-IT) 2009-06--> 15T13:45:30: (ja-JP) |
" or " | The date separator. More information: the custom format specifier "/". | 2009-06-15T13: 45: 30 -> / (en-US) 2009-06 -> 15T13: 45: 30 - (ar-DZ) 2009-06--> 15T13:45:30. (tr-TR) |
"sequence" 'sequence' | Literal string delimiter. More information: Character Literals. | 2009-06-15T13: 45: 30 ("arr:" h: mt) -> arr: 1: 45 P 2009-06-15T13: 45: 30 ('Arr:' h: mt) -> Arr: 1: 45 P |
% | Defines the following character as a custom format specifier. More information:using simple custom format specifiers. | 2009-06-15T13:45:30 (%h) -> 1 |
\ | The escape character. More information: Character Literals e using the escape character. | 2009-06-15T13: 45: 30 (h \ h) -> 1 h |
Any other character | The character is copied to the unchanged result string. More information: Character Literals. | 2009-06-15T01: 45: 30 (Arr hh: mm t) -> Arr 01: 45 a |
Great post!
It helped me optimize hundreds of queries in which I was doing three conversions per record to bring in currency format.
Congratulations!
Thank you, Piero.
I hope it was helpful to you 🙂
Hug
Show!
Just a doubt, in situations where the date comes as varchar, should I use the converter anyway?
SET LANGUAGE 'Brazilian'
Decare
@Date AS VARCHAR (8);
SET
@Data = '20171017'
SELECT FORMAT (CAST (@Data AS DATETIME), 'D')
Christian,
If it is interesting to change the formatting of the next date in string format (varchar), you can use the FORMAT function, yes.