Extracting Date from SQL Server datetime

I was working on a project yesterday that required me to get a date from a SQL Server datetime field. I needed it to return just the date (not the time), but for the life of me I couldn't figure it out (don't worry about why, just go with me here).

I called my good friend (and local SQL Server answer-man), Will Spurgeon. As usual, he came through for me. I never would have guessed the answer:

[More]

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Wouldn't this provide the same functionality with less overhead?

SELECT convert(smalldatetime, mydatecol) AS mydatecol
FROM mytable
WHERE id=1

Jason

# Posted By | 2/3/05 4:29 AM
Sorry Jason, I just tested it and it didn't work.
# Posted By | 2/3/05 5:29 PM
Thanks, your code is works!
# Posted By satiri | 10/24/05 4:22 AM
This method runs much faster, especially when running a large number of records

SELECT CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, mydatecol))) AS mydatecol
FROM mytable
WHERE id=1
# Posted By Jim Banks | 10/30/06 4:02 PM
Works Like a charm!!! just in time to save me from a major headache
# Posted By Spice and Gold Coins | 12/14/06 3:24 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.