Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Need to have Date Part return hour in 12 hour format

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-21 : 10:23:58
RS writes "I am using date part function to format date in a specific format I need. The date part for hour returns the hour in 24 hour format, whereas I need it in 12 hour format. Tried a lot of things, but nothing works. I know I can add a IF condition that checks if hour is greater than 12 then it will deduct 12 from it and display it, but I am looking for something more sophisticated way. Please help
Thanks,
RS"

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-04-21 : 10:55:50
select case when datepart(hh, getdate()) > 12 then datepart(hh, getdate()) - 12 else datepart(hh, getdate()) end


Duane.
Go to Top of Page
   

- Advertisement -