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:
SELECT convert(smalldatetime, mydatecol) AS mydatecol
FROM mytable
WHERE id=1
Jason
SELECT CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, mydatecol))) AS mydatecol
FROM mytable
WHERE id=1