2

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

  • Date is not a valid type in SQL server 2005 (Msg 243, Level 16, State 1, Line 1 Type date is not a defined system type.) –  Jul 15 '14 at 13:07
  • Or use `select substring('2014-07-15 15:01:16.880', 1, 10)` :) – juergen d Jul 15 '14 at 13:13

2 Answers2

2

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
Bridge
  • 29,818
  • 9
  • 60
  • 82
0

You could use CONVERT to do the conversion.

SELECT CONVERT('2014-07-15 15:01:16.880', GETDATE(), 112)
Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265