SQL Server/T-SQL/Date Timezone/DATEPART
Содержание
- 1 DATEPART(dw,GETDATE())
- 2 DATEPART(m,GETDATE())
- 3 DATEPART(mi,GETDATE())
- 4 DATEPART(month, "4-29-1988")
- 5 DATEPART(n,GETDATE())
- 6 DATEPART: return part of a date as an integer value
- 7 Dateparts and Abbreviations
- 8 DATEPART(wk,GETDATE())
- 9 DATEPART(yy,GETDATE())
- 10 select DATEPART(dayofyear, "2002-35:00")
- 11 select DATEPART(quarter, "2002-35:00")
- 12 select DATEPART(week, "2002-35:00")
- 13 select DATEPART(weekday, "2002-35:00")
DATEPART(dw,GETDATE())
1>
2> SELECT DATEPART(dw,GETDATE())
3> GO
-----------
5
(1 rows affected)
DATEPART(m,GETDATE())
1>
2> SELECT DATEPART(m,GETDATE())
3> GO
-----------
10
(1 rows affected)
DATEPART(mi,GETDATE())
1>
2> SELECT DATEPART(mi,GETDATE())
3> GO
-----------
15
(1 rows affected)
DATEPART(month, "4-29-1988")
1>
2>
3>
4> -- DATEPART() returns an integer value
5>
6>
7>
8> SELECT DATEPART(month, "4-29-1988")
9> GO
-----------
4
(1 rows affected)
DATEPART(n,GETDATE())
1>
2> SELECT DATEPART(n,GETDATE())
3> GO
-----------
15
(1 rows affected)
DATEPART: return part of a date as an integer value
45> -- DATEPART: return part of a date as an integer value.
46>
47> -- DATEPART(part_of_the_date_to_return, the_date)
48>
49> SELECT DATEPART(dw,GETDATE())
50> GO
-----------
5
(1 rows affected)
Dateparts and Abbreviations
Datepart Abbreviation
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
weekday dw
hour hh
minute mi, n
second ss, s
millisecond ms
DATEPART(wk,GETDATE())
1>
2> SELECT DATEPART(wk,GETDATE())
3> GO
-----------
41
(1 rows affected)
DATEPART(yy,GETDATE())
1>
2> SELECT DATEPART(yy,GETDATE())
3> GO
-----------
2006
(1 rows affected)
select DATEPART(dayofyear, "2002-35:00")
3> select DATEPART(dayofyear, "2002-09-30 11:35:00")
4> GO
-----------
273
(1 rows affected)
1>
select DATEPART(quarter, "2002-35:00")
3> select DATEPART(quarter, "2002-09-30 11:35:00")
4> GO
-----------
3
(1 rows affected)
1>
select DATEPART(week, "2002-35:00")
3> select DATEPART(week, "2002-09-30 11:35:00")
4> GO
-----------
40
(1 rows affected)
select DATEPART(weekday, "2002-35:00")
2> select DATEPART(weekday, "2002-09-30 11:35:00")
3> GO
-----------
2
(1 rows affected)