Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server datetime data type does not allow many formats

I have a table in SQL Server 2005 which has a date time field. I want to save the date time value in mm/dd/yyyy hh:mm:ss format, but I guess SQL Server allows date time in yyyy-mm-dd HH:mm:ss.ll format.

I can save date time value in mm/dd/yyyy hh:mm:ss format as a varchar, but that defeats my intention of sorting the table on that date time field.

Is there something missing in my approach? Any suggestions?

cheers

like image 295
Arnkrishn Avatar asked Apr 16 '26 13:04

Arnkrishn


1 Answers

The datetime type does not store it in yyyy-mm-dd HH:mm:ss.ll, as you claim.

Datetime columns are stored as 8-byte binary data. The yyyy-mm-dd HH:mm:ss.ll format is just how it's returned in your query. To display it in other formats, look at the CONVERT function.

like image 90
Joel Coehoorn Avatar answered Apr 19 '26 23:04

Joel Coehoorn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!