Convert datetime to smalldatetime in SQL stored procedure that preserves the time?

311 Views Asked by At

I have a stored procedure that gets data from a database that utilizes a column with type datetime (there is a valid time value in it) and it updates a table in another database that happens to use the smalldatetime type. When trying to convert from the datetime type to the smalldatetime type, I'm losing the time portion of the date. For some strange reason the date is being rounded up by a day on me. Is there some sort of special convert statement from datetime to smalldatetime that preserves the time portion of that date value?

1

There are 1 best solutions below

1
CurlyShuffle On

Apparently after digging around more I found the answer to my question. The smalldatetime data type rounds the seconds. If it's :29 and below, it goes to the previous minute. If it's :30 and above, it goes to the next minute. I wasn't aware of this previously. What's really goofy is that you still see the seconds value in the database even though it's always :00.