The style parameter of convert provides a variety of date display formats for converting datetime or smalldatetime data to char or varchar. The number argument you supply as the style parameter determines how the data is displayed. The year can be displayed in either 2 digits or 4 digits. Add 100 to a style value to get a 4-digit year, including the century (yyyy).
Following is a table of the possible values for style and the variety of date formats you can use. When you use style with smalldatetime, the styles that include seconds or milliseconds will show zeros in those positions.
Without Century (yy) | With Century (yyyy) |
|
|
---|---|---|---|
- | 0 or 100 | Default | mon dd yyyy hh:mm AM (or PM) |
1 | 101 | USA | mm/dd/yy |
2 | 2 | SQL standard | yy.mm.dd |
3 | 103 | English/French | dd/mm/yy |
4 | 104 | German | dd.mm.yy |
5 | 105 | dd-mm-yy | |
6 | 106 | dd mon yy | |
7 | 107 | mon dd, yy | |
8 | 108 | hh:mm:ss | |
- | 9 or 109 | Default + milliseconds | mon dd yyyy hh:mm:sss AM (or PM) |
10 | 110 | USA | mm-dd-yy |
11 | 111 | Japan | yy/mm/dd |
12 | 112 | ISO | yymmdd |
The default values, style 0 or 100, and 9 or 109, always return the century (yyyy).
Following is an example of the use of convert's style parameter:
select convert(char(12), getdate(), 3)
This converts the current date to style 3, dd/mm/yy.