DATEPART() SQL Server function Statement:
DATEPART(datepart,date)
declare @ThisDate datetime
set @ThisDate='2012-08-30 08:45:08.717'
select ('yy')DATEPARTInit,('year')UseForShow,DATEPART(yy,@ThisDate)ShowData Union
select ('qq'),('quarter'),DATEPART(qq,@ThisDate) Union
select ('mm'),('month'),DATEPART(mm,@ThisDate) Union
select ('dy'),('dayofyear'),DATEPART(dy,@ThisDate) Union
select ('dd'),('day'),DATEPART(dd,@ThisDate) Union
select ('wk'),('week'),DATEPART(wk,@ThisDate) Union
select ('dw'),('weekday'),DATEPART(dw,@ThisDate) Union
select ('hh'),('hour'),DATEPART(hh,@ThisDate) Union
select ('mi'),('minute'),DATEPART(mi,@ThisDate) Union
select ('ss'),('second'),DATEPART(ss,@ThisDate) Union
select ('ms'),('second'),DATEPART(ms,@ThisDate) --union
--select ('mcs'),('microsecond'),DATEPART(mcs,@ThisDate) union
--select ('ns'),('nanosecond'),DATEPART(ns,@ThisDate)
#Results:
DatePartInit UseForShow ShowData
dd day 30
dw weekday 5
dy dayofyear 243
hh hour 8
mi minute 45
mm month 8
ms second 717
qq quarter 3
ss second 8
wk week 35
yy year 2012
Tidak ada komentar:
Posting Komentar