Friday, March 09, 2012

tsql get part of a datetime value

DATEPART(portion, datetimevalue)

the options for portion are:

Ms for Milliseconds
Yy for Year
Qq for Quarter of the Year
Mm for Month
Dy for the Day of the Year
Dd for Day of the Month
Wk for Week
Dw for the Day of the Week
Hh for Hour
Mi for Minute
Ss for Second

e.g.
select startdate,DATEPART(Hh,a.startdate)

this returns the hour of startdate

No comments: