DATEPART
Returns an integer representing the specified datepart of the specified date.
Syntax
DATEPART ( datepart , date )
Arguments
datepart
Is the parameter that specifies the part of the date to return. The table lists dateparts and abbreviations recognized by Microsoft® SQL Server™.
Datepart Abbreviations
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
I recommend using a 24 hour time for comparisons rather than a 12 hour time with AM or PM. The 24 hour time can be easily derived using the convert function and style 108.
Select convert(varchar(11),getdate(),108)
If you need the AM/PM form of the time you can use a query like the following.
Select
Right(Convert(Varchar(19), getdate(), 20), 8) +
Case
When datepart(hh, getdate())>11
Then ' PM' Else ' AM' End
NOTE: In Each case the date becomes a character data type so comparisons will only work if all times are converted. Terry L. Broadbent Programming and Computing Resources
AND convert(varchar,TR_Basket_Header1.TS_End_Time,108) >= convert(varchar,@CurPerTS_Start_Date,108)
AND convert(varchar,TR_Basket_Header1.TS_End_Time,108) <= convert(varchar,@CurPerTS_End_Date,108)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.