troubleshooting Question

sql server 2008 datetime data types

Avatar of maqskywalker
maqskywalker asked on
Microsoft SQL ServerMicrosoft SQL Server 2008
6 Comments6 Solutions770 ViewsLast Modified:
hi experts,

I'm using sql server 2008 R2.

When I run this query:


DECLARE @datetime datetime = '2013-04-05 16:32:35';

DECLARE @datetime2 datetime2 = @datetime;
DECLARE @smalldatetime smalldatetime = @datetime;

SELECT @datetime2 AS '@datetime2', @datetime AS '@datetime', @smalldatetime AS '@smalldatetime';

I get the following result:

query result
What data type should I use to represent a date time value that looks like this?:

2013-04-05 16:32:35

I thought I was supposed to use smalldatetime data type.
But if you look at the image of my query above, when i use that data type the seconds are rounded up.

Am I missing something?
Why are the seconds rounded up in the smalldatetime datatype?

thanks.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 6 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 6 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros