Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Datetime to smalldatetime

Author  Topic 

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2009-10-23 : 04:19:08
How on earth do you do a conversion on this?

I tried
convert(smalldatetime, @startdate,101)
but to be honest I don't know what I am doing


Can you do a comparison with smalldatetime in SQL like
@smalldatetimea > @smalldatetimeb?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-23 : 04:38:14
you can just assign it, no conversion required. SQL Server will implicitly convert this

select smalldatetime_col = datetime_col



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2009-10-23 : 06:46:18
Thanks chief.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-10-23 : 10:13:18
You should be aware of the rules for how DATETIME is rounded up or down when you convert to SMALLDATETIME. If seconds is less than 30, it is rounded down to the nearest minute, otherwise it is rounded up.

select
DT,
SDT = convert(smalldatetime, DT )
from
(
select DT = convert(datetime,'2009-10-23 10:05:29.997') union all
select DT = convert(datetime,'2009-10-23 10:05:30.000')
) a

Results:
DT                      SDT
----------------------- -------------------
2009-10-23 10:05:29.997 2009-10-23 10:05:00
2009-10-23 10:05:30.000 2009-10-23 10:06:00

(2 row(s) affected)


CODO ERGO SUM
Go to Top of Page
   

- Advertisement -