Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i m using the following query in my store procedure that is showing the time in hpus,minute, second format....

SELECT LTRIM(RIGHT(CONVERT(VARCHAR(20), GETDATE(), 100), 7))

...
I want a query that will show time only in HOUR (12 hour format)...(EX. 5AM)

thanx in advance
Posted

SQL
SELECT CASE WHEN DATEPART( HH , GETDATE()) > 12 THEN CAST ( ( DATEPART( HH , GETDATE())  % 12 ) AS VARCHAR) + ' PM'
            ELSE  CAST ( ( DATEPART( HH , GETDATE())   ) AS VARCHAR) + 'AM'
        END AS HourParam
 
Share this answer
 
Comments
ridoy 24-Sep-12 10:48am    
excellent..+5
u may try it this way too..

SELECT substring((CONVERT(varchar(20),GETDATE(), 100)),14,(len(CONVERT(varchar(12),GETDATE(), 100)))) 


hope this help u..

thanx
 
Share this answer
 
hi,
i think you can do something like that the query you are using gives you 05:00am then you can use substring to get your desired result.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900