Sql server® 2012 t-sql fundamentals



Download 10,93 Mb.
Pdf ko'rish
bet127/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   123   124   125   126   127   128   129   130   ...   443
Bog'liq
BookSQL

date and Time Functions

In this section, I describe functions that operate on date and time data types, including GETDATE



CURRENT_TIMESTAMPGETUTCDATESYSDATETIMESYSUTCDATETIMESYSDATETIMEOFFSETCAST

CONVERTSWITCHOFFSETTODATETIMEOFFSETDATEADDDATEDIFFDATEPARTYEARMONTH

DAYDATENAME, various FROMPARTS functions, and EOMONTH

The functions SYSDATETIMESYSUTCDATETIMESYSDATETIMEOFFSETSWITCHOFFSET, and 



TODATETIMEOFFSET were introduced in SQL Server 2008. Existing functions were enhanced 

to sup port the newer types and parts. The various FROMPARTS functions and the EOMONTH 

function were introduced in SQL Server 2012. 

Current date and Time

The following niladic (parameterless) functions return the current date and time values in the system 

where the SQL Server instance resides: GETDATECURRENT_TIMESTAMPGETUTCDATESYSDATETIME

SYSUTCDATETIME, and SYSDATETIMEOFFSET. Table 2-3 provides the description of these functions.

TABLE 2-3

  Functions Returning Current Date and Time



Function

Return Type

Description

GETDATE

DATETIME

Current date and time



CURRENT_TIMESTAMP

DATETIME

Same as GETDATE but ANSI SQL–compliant



GETUTCDATE

DATETIME

Current date and time in UTC



SYSDATETIME

DATETIME2

Current date and time



SYSUTCDATETIME

DATETIME2

Current date and time in UTC



SYSDATETIMEOFFSET

DATETIMEOFFSET

Current date time including time zone

Note that you need to specify empty parentheses with all functions that should be specified with out 

parentheses, except the ANSI function CURRENT_TIMESTAMP. Also, because CURRENT_TIMESTAMP 

and GETDATE return the same thing but only the former is standard, it is recommended that you use 

the former. This is a practice that I try to follow in general—when I have several options that do the 

same thing with no functional or performance difference, and one is standard but others aren’t, my 

preference is to use the standard option.

The following code demonstrates using the current date and time functions.

SELECT 


  GETDATE()           AS [GETDATE], 

  CURRENT_TIMESTAMP   AS [CURRENT_TIMESTAMP], 

  GETUTCDATE()        AS [GETUTCDATE], 

  SYSDATETIME()       AS [SYSDATETIME], 

  SYSUTCDATETIME()    AS [SYSUTCDATETIME], 

  SYSDATETIMEOFFSET() AS [SYSDATETIMEOFFSET];

www.it-ebooks.info




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   123   124   125   126   127   128   129   130   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish