Date and Time Styles When expression is a date or time data type, style can be one of the values shown in the following table. Other values are processed as 0. SQL Server supports the date format in Arabic style by using the Kuwaiti algorithm.
Without century (yy) (1) | With century (yyyy) | Standard | Input/Output (3) |
- | 0 or 100 (1, 2) | Default | mon dd yyyy hh:miAM (or PM) |
1 | 101 | U.S. | mm/dd/yyyy |
2 | 102 | ANSI | yy.mm.dd |
3 | 103 | British/French | dd/mm/yyyy |
4 | 104 | German | dd.mm.yy |
5 | 105 | Italian | dd-mm-yy |
6 | 106 (1) | - | dd mon yy |
7 | 107 (1) | - | Mon dd, yy |
8 | 108 | - | hh:mi:ss |
- | 9 or 109 (1, 2) | Default + milliseconds | mon dd yyyy hh:mi:ss:mmmAM (or PM) |
10 | 110 | USA | mm-dd-yy |
11 | 111 | JAPAN | yy/mm/dd |
12 | 112 | ISO | yymmdd yyyymmdd |
- | 13 or 113 (1, 2) | Europe default + milliseconds | dd mon yyyy hh:mi:ss:mmm(24h) |
14 | 114 | - | hh:mi:ss:mmm(24h) |
- | 20 or 120 (2) | ODBC canonical | yyyy-mm-dd hh:mi:ss(24h) |
- | 21 or 121 (2) | ODBC canonical (with milliseconds) | yyyy-mm-dd hh:mi:ss.mmm(24h) |
- | 126 (4) | ISO8601 | yyyy-mm-ddThh:mi:ss.mmm (no spaces) |
- | 127(6, 7) | ISO8601 with time zone Z. | yyyy-mm-ddThh:mi:ss.mmmZ (no spaces) |
- | 130 (1, 2) | Hijri (5) | dd mon yyyy hh:mi:ss:mmmAM |
- | 131 (2) | Hijri (5) | dd/mm/yy hh:mi:ss:mmmAM |
1 These style values return nondeterministic results. Includes all (yy) (without century) styles and a subset of (yyyy) (with century) styles.
2 The default values (style 0 or 100, 9 or 109, 13 or 113, 20 or 120, and 21 or 121) always return the century (yyyy).
3 Input when you convert to datetime; output when you convert to character data.
4 Designed for XML use. For conversion from datetime or smalldatetime to character data, the output format is as described in the previous table.
5 Hijri is a calendar system with several variations. SQL Server uses the Kuwaiti algorithm.
Örnekler:
Select convert(varchar, getdate(), 14) - Saat + saniye+ milisaniye
Result: 09:35:10:730
Select convert(varchar(5), getdate(), 14) -- SaatResult: 09:35
select CONVERT(VARCHAR(20) , getdate(), 103)Result : 21/07/2022
DECLARE @Tarih VARCHAR(10)
Set @Tarih=CONVERT(VARCHAR(10) , getdate(), 103)Print @TarihResult: 21/07/2022
set @Tarih=CONVERT(DateTime,'2011-01-01', 102)print @TarihResult : Oca 1 2011 12:00AM
Set @Tarih=CONVERT(VARCHAR(10) , getdate(), 111)print @TarihResult: 2011/07/06
DATE FORMATS
Format # Query (current date: 12/30/2006) Sample
1 select convert(varchar, getdate(), 1) 12/30/06
2 select convert(varchar, getdate(), 2) 06.12.30
3 select convert(varchar, getdate(), 3) 30/12/06
4 select convert(varchar, getdate(), 4) 30.12.06
5 select convert(varchar, getdate(), 5) 30-12-06
6 select convert(varchar, getdate(), 6) 30 Dec 06
7 select convert(varchar, getdate(), 7) Dec 30, 06
10 select convert(varchar, getdate(), 10) 12-30-06
11 select convert(varchar, getdate(), 11) 06/12/30
101 select convert(varchar, getdate(), 101) 12/30/2006
102 select convert(varchar, getdate(), 102) 2006.12.30
103 select convert(varchar, getdate(), 103) 30/12/2006
104 select convert(varchar, getdate(), 104) 30.12.2006
105 select convert(varchar, getdate(), 105) 30-12-2006
106 select convert(varchar, getdate(), 106) 30 Dec 2006
107 select convert(varchar, getdate(), 107) Dec 30, 2006
110 select convert(varchar, getdate(), 110) 12-30-2006
111 select convert(varchar, getdate(), 111) 2006/12/30
TIME FORMATS
8 or 108 select convert(varchar, getdate(), 8) 00:38:54
9 or 109 select convert(varchar, getdate(), 9) Dec 30 2006 12:38:54:840AM
14 or 114 select convert(varchar, getdate(), 14) 00:38:54:840
You can also format the date or time without dividing characters, as well as concatenate the date and time string:
Sample statement Output
select replace(convert(varchar, getdate(),101),'/','') 12302006
select replace(convert(varchar, getdate(),101),'/','') + replace(convert(varchar, getdate(),108),':','') 12302006004426
DATE FORMATS | ||
Format # | Query (current date: 12/30/2006) | Sample |
1 | select convert(varchar, getdate(), 1) | 12/30/06 |
2 | select convert(varchar, getdate(), 2) | 06.12.30 |
3 | select convert(varchar, getdate(), 3) | 30/12/06 |
4 | select convert(varchar, getdate(), 4) | 30.12.06 |
5 | select convert(varchar, getdate(), 5) | 30-12-06 |
6 | select convert(varchar, getdate(), 6) | 30 Dec 06 |
7 | select convert(varchar, getdate(), 7) | Dec 30, 06 |
10 | select convert(varchar, getdate(), 10) | 12-30-06 |
11 | select convert(varchar, getdate(), 11) | 06/12/30 |
101 | select convert(varchar, getdate(), 101) | 12/30/2006 |
102 | select convert(varchar, getdate(), 102) | 2006.12.30 |
103 | select convert(varchar, getdate(), 103) | 30/12/2006 |
104 | select convert(varchar, getdate(), 104) | 30.12.2006 |
105 | select convert(varchar, getdate(), 105) | 30-12-2006 |
106 | select convert(varchar, getdate(), 106) | 30 Dec 2006 |
107 | select convert(varchar, getdate(), 107) | Dec 30, 2006 |
110 | select convert(varchar, getdate(), 110) | 12-30-2006 |
111 | select convert(varchar, getdate(), 111) | 2006/12/30 |
TIME FORMATS | ||
8 or 108 | select convert(varchar, getdate(), 8) | 00:38:54 |
9 or 109 | select convert(varchar, getdate(), 9) | Dec 30 2006 12:38:54:840AM |
14 or 114 | select convert(varchar, getdate(), 14) | 00:38:54:840 |
You can also format the date or time without dividing characters, as well as concatenate the date and time string:
Sample statement | Output |
select replace(convert(varchar, getdate(),101),'/','') | 12302006 |
select replace(convert(varchar, getdate(),101),'/','') + replace(convert(varchar, getdate(),108),':','') | 12302006004426 |
Hiç yorum yok:
Yorum Gönder