Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time

Status
Not open for further replies.

DrSql

Programmer
Jul 16, 2000
615
US
Is any possible way to conver this in AM PM hours.

select datepart(hh,getdate())

8=8AM
10=10AM
12=12PM
14=02PM
16=04PM
18=06PM
23=11PM
24=12AM

Thanks

Dr. Sql
goEdeveloper@yahoo.com
Good Luck.
 
This is ugly, but should work well for you.

Code:
Declare @TestDate DateTime

Set @TestDate = '23:59'

Select Convert(VarChar(10), 
			Case	When (datepart(hour, @TestDate) % 12) = 0
					Then 12
					Else DatePart(hour, @TestDate) % 12
					End
			)
			+ Case 	When DatePart(hour, @TestDate)  < 12 
					Then ' AM' 
					Else ' PM' 
					End

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top