Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL convert DateTime to Date (SQL server 2005) [duplicate]

I want to convert this: 2014-07-15 15:01:16.880

To: 2014-07-15

Or to: 2014-07-15 00:00:00:000

What is the best way to do this?

By the way, My database is inside a Microsoft SQL 2005 Server

Thanks in advance


1 Answers

There is no Date datatype in SQL Server 2005, it was added in SQL Server 2008.

To go with your second alternative, you can truncate the datetime to midnight on the same day:

SELECT DATEADD(DAY, DATEDIFF(DAY,0, YourDateColumn), 0)
FROM   YourTable
like image 184
Bridge Avatar answered Feb 22 '26 12:02

Bridge



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!