SQL Server/T-SQL/Date Timezone/DATEPART — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:46, 26 мая 2010
Содержание
- 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())
<source lang="sql">
1> 2> SELECT DATEPART(dw,GETDATE()) 3> GO
5
(1 rows affected)
</source>
DATEPART(m,GETDATE())
<source lang="sql">
1> 2> SELECT DATEPART(m,GETDATE()) 3> GO
10
(1 rows affected)
</source>
DATEPART(mi,GETDATE())
<source lang="sql">
1> 2> SELECT DATEPART(mi,GETDATE()) 3> GO
15
(1 rows affected)
</source>
DATEPART(month, "4-29-1988")
<source lang="sql">
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)
</source>
DATEPART(n,GETDATE())
<source lang="sql">
1> 2> SELECT DATEPART(n,GETDATE()) 3> GO
15
(1 rows affected)
</source>
DATEPART: return part of a date as an integer value
<source lang="sql">
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)
</source>
Dateparts and Abbreviations
<source lang="sql">
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
</source>
DATEPART(wk,GETDATE())
<source lang="sql">
1> 2> SELECT DATEPART(wk,GETDATE()) 3> GO
41
(1 rows affected)
</source>
DATEPART(yy,GETDATE())
<source lang="sql">
1> 2> SELECT DATEPART(yy,GETDATE()) 3> GO
2006
(1 rows affected)
</source>
select DATEPART(dayofyear, "2002-35:00")
<source lang="sql">
3> select DATEPART(dayofyear, "2002-09-30 11:35:00") 4> GO
273
(1 rows affected) 1>
</source>
select DATEPART(quarter, "2002-35:00")
<source lang="sql">
3> select DATEPART(quarter, "2002-09-30 11:35:00") 4> GO
3
(1 rows affected) 1>
</source>
select DATEPART(week, "2002-35:00")
<source lang="sql">
3> select DATEPART(week, "2002-09-30 11:35:00") 4> GO
40
(1 rows affected)
</source>
select DATEPART(weekday, "2002-35:00")
<source lang="sql">
2> select DATEPART(weekday, "2002-09-30 11:35:00") 3> GO
2
(1 rows affected)
</source>