1, returns the current date and time
-
select
GETDATE()
'当前日期-精确到33毫秒'
-
-
select
GETUTCDATE()
'UTC日期和时间-精确到33毫秒'
-
-
select SYSDATETIME()
'当前日期和时间-精确到100纳秒(高精度)'
-
-
select
SYSUTCDATETIME()
'UTC-精确到100纳秒(高精度)'
-
-
select
SYSDATETIMEOFFSET()
'当前日期与UTC之间的差值(时分)'
2, conversion offset from one into another, from the UTC-05: 00 Switch UTC + 03: 00:
'2007-08-1210: 20: 35.9788989' is UTC minus '05: 00 'counted out after,
so UTC is' 2007-08-1210: 20: 35.9788989 'plus '05: 00',
that is, '2007-08-1215: 20: 35.9788989',
then '2007-08-1215: 20: 35.9788989' plus '03: 00 ',
which is' 2007-08-1218: 20: 35.9788989'
select SWITCHOFFSET('2007-08-12 10:20:35.9788989 -05:00','+03:00')
The common date and time based to date time offset, the offset value only increased after the date and time to return: 2007-08-1210: 20: 35.0000000 -05: 00
select TODATETIMEOFFSET('2007-08-12 10:20:35','-05:00')
3, part of the date display string
-
select SYSDATETIME(),
-
DATENAME(
year,SYSDATETIME()),
-
DATENAME(
quarter,SYSDATETIME()),
-
DATENAME(
month,SYSDATETIME()),
-
-
DATENAME(
dayofyear,SYSDATETIME()),
-
DATENAME(
day,SYSDATETIME()),
-
-
DATENAME(
week,SYSDATETIME()),
-
DATENAME(
weekday,SYSDATETIME()),
-
-
DATENAME(
hour,SYSDATETIME()),
-
DATENAME(
minute,SYSDATETIME()),
-
DATENAME(
second,SYSDATETIME()),
-
DATENAME(millisecond,SYSDATETIME()),
-
DATENAME(
microsecond,SYSDATETIME()),
-
DATENAME(nanosecond,SYSDATETIME()),
-
-
DATENAME(TZoffset,SYSDATETIME()),
-
DATENAME(ISO_WEEK,SYSDATETIME())
4, part of the date display integer
-
select
YEAR(
GETDATE()),
-
MONTH(
getdate()),
-
DAY(
getdate())
-
-
-
select SYSDATETIME(),
-
DATEPART(
year,SYSDATETIME()),
-
DATEPART(
quarter,SYSDATETIME()),
-
DATEPART(
month,SYSDATETIME()),
-
-
DATEPART(
dayofyear,SYSDATETIME()),
-
DATEPART(
day,SYSDATETIME()),
-
-
DATEPART(
week,SYSDATETIME()),
-
DATEPART(
weekday,SYSDATETIME()),
-
-
DATEPART(
hour,SYSDATETIME()),
-
DATEPART(
minute,SYSDATETIME()),
-
DATEPART(
second,SYSDATETIME()),
-
-
DATEPART(millisecond,SYSDATETIME()),
-
DATEPART(
microsecond,SYSDATETIME()),
-
DATEPART(nanosecond,SYSDATETIME()),
-
DATEPART(TZoffset,SYSDATETIME()),
-
DATEPART(ISO_WEEK,SYSDATETIME())
5, increase, decrease date value
-
SELECT
DATEADD(
quarter,
1,
getdate()),
-
DATEADD(
quarter,
-1,
getdate())
6, the difference between the two dates
-
select
DATEDIFF(
DAY,
'2011-08-09',
GETDATE()),
-
DATEDIFF(
MONTH,
'2011-08-09',
GETDATE())