Avatar of maqskywalker
maqskywalker
 asked on

sql server 2008 datetime data types

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.
Microsoft SQL ServerMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
Anthony Perkins

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Scott Pletcher

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Robert Schutt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Your help has saved me hundreds of hours of internet surfing.
fblack61