Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have created a table in sql server with the datatype "time". when i insert any value to this table, it shows like hh:mm:ss.----- format. For Example- if i insert 09:30 it will come like 09:30:00.000-----
i want to convert 09:30:00.000 to 09:30AM/PM with the help of trigger i.e. when i insert any value it should convert in (varchar/09:30AM/PM) format.
Posted
Comments
CHill60 6-May-15 7:57am    
It is not stored with a format. It is only the display that is showing like that and you wouldn't use a trigger for display purposes. Just do the formatting of the time when you want to display the results,

1 solution

SQL does not store time (and date) values formatted, but in binary. The format you see is part of the functionality of the client you use to display the value...So if you want to display a time value in your application in a specific format you may use DateTime.ToString[^] method...
For the sample you mentioned you may use the string "hh:mm tt"...
More info about format strings:
https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx[^]
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]
 
Share this answer
 
Comments
Nikunj Bhanushali 6-May-15 13:25pm    
Data is always stored in the database in a specific way. This applies to "Time" as well. This cannot be changed , instead whenever displaying the Time value you can convert the format as you wish.

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