Click here to Skip to main content
15,889,861 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a TIME datatype field in sql database,

its storing 24 hour format,i want the value in 12 hour format


Help me to convert it to 12 hour format
Posted

Time fields are not stored in 12 or 24 hour format: they are stored in terms of milliseconds (or other small interval) since midnight.

When you retrieve and display the time, your default formatting is set to 24 hour. Override it with ToString("hh:mm tt") instead of ToString().
 
Share this answer
 
To add to OriginalGriff's answer, if you want to do the conversion using SQL you could try CONVERT[^]. For example:
SELECT CONVERT(varchar, SomeTimeField, 9) FROM ...
 
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