Latest Posts

Permanent Solution to an old Problem

Posted on December 31, 2007, under ColdFusion, SQL Server | 4034 Views

One of the rare issues came up today where I need to extract the date only from a datetime field.

I remembered part of it but still had to google for a second to get the other pieces. Now, I'm posting the syntax here so I don't have to go hunting for it later.

Bottom Line:

CAST(FLOOR(CAST(YOURFIELD AS float))AS datetime) as dt_newField

The reason this is becoming an issue is the App this db serves is a thirdparty app so I'm going to not have much success in making changes. I''m thinking about a insert trigger to all the system to cleanup the data going in and store the time records in another field.

Ben Nadel has a copy of posts up about this: Ask Ben: Getting Only the Date Part of a Date/Time Stamp in SQL Server

And then he follows that up with this little beauty, Ask Ben: Comparing Only Times in SQL

The Truth is out there.