Wednesday, March 7, 2012

get the AM/PM value stored in a database

How do I just return if a datetime field is AM or PM from sql server?
thanx
weisenbrI believe you have to use DATEDIFF and get the number of seconds elapsed since the last midnight. Then, if it's greater than 12x60x60 = 43,200, it's PM|||Depending on where you are trying to do it something like this would work:

SELECT CASE WHEN DATEPART(hh,getdate()) > 11 THEN 'PM' ELSE 'AM' END

No comments:

Post a Comment