April 10, 2013 at 11:03 pm
Comments posted to this topic are about the item DateTime data types
April 10, 2013 at 11:14 pm
Thanks for start my day with an easy question.
Still i found result as "Correct answers: 100%"
Nice question, keep it up my friend !!!
🙂
Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
April 11, 2013 at 1:47 am
Really good question 🙂
+1
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
April 11, 2013 at 1:33 pm
Got it right by elimination. There is no way a NULL value would be converted to an actual date (as far as I know, at least), so that eliminates answer B. Date types can't return an empty string (that would have to be char, varchar, etc.), so that eliminates answer A.
However, I never memorized the date that is equivalent to 0 and I didn't know if datetime, datetime2 and date had different conversions from integers, so if there had been an answer such as NULL, 1900-01-01 00:00:000, 1753-01-01 00:00:000, 1900-01-01, I might had gotten it wrong. Guess I learned that much from this question, then.
Thanks, Sasidhar Pulivarthi! 😀
Edit: changed "don't know if datetime (...) have different conversions from integers" to "didn't know", which made me realized I actually learned something new here. :w00t:
April 11, 2013 at 3:46 pm
If default values are returned as in your explaination why are not all the values except null returned in this format, "1900-01-01 00:00:00.0000000". How did they get switched to "Jan 1 1900 12:00AM"?
April 11, 2013 at 3:51 pm
Thanks
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 11, 2013 at 11:23 pm
Primo Dang (4/11/2013)
Got it right by eliminationThanks, Sasidhar Pulivarthi! 😀
+1
Thanks for the question ..
~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one :ermm:
April 11, 2013 at 11:32 pm
jlennartz (4/11/2013)
If default values are returned as in your explaination why are not all the values except null returned in this format, "1900-01-01 00:00:00.0000000". How did they get switched to "Jan 1 1900 12:00AM"?
the default conversion style for cast and convert is 0 for datetime and 121 for datetime2 ; that's how !!
ref: http://msdn.microsoft.com/en-gb/library/ms187928.aspx
~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one :ermm:
April 12, 2013 at 1:57 am
Primo Dang (4/11/2013)
Got it right by elimination. There is no way a NULL value would be converted to an actual date (as far as I know, at least), so that eliminates answer B. Date types can't return an empty string (that would have to be char, varchar, etc.), so that eliminates answer A.However, I never memorized the date that is equivalent to 0 and I didn't know if datetime, datetime2 and date had different conversions from integers, so if there had been an answer such as NULL, 1900-01-01 00:00:000, 1753-01-01 00:00:000, 1900-01-01, I might had gotten it wrong. Guess I learned that much from this question, then.
Thanks, Sasidhar Pulivarthi! 😀
Edit: changed "don't know if datetime (...) have different conversions from integers" to "didn't know", which made me realized I actually learned something new here. :w00t:
i too memorize if we use datatime2 datatype that gives the datetime value as '1900-01-01 00:00:00.0000000 '. That is the reason to clicked the third answer... it's correct.....
thanks for this question.. nice one....
Manik
You cannot get to the top by sitting on your bottom.
April 12, 2013 at 10:24 am
demonfox (4/11/2013)
jlennartz (4/11/2013)
If default values are returned as in your explaination why are not all the values except null returned in this format, "1900-01-01 00:00:00.0000000". How did they get switched to "Jan 1 1900 12:00AM"?the default conversion style for cast and convert is 0 for datetime and 121 for datetime2 ; that's how !!
Thank You
April 12, 2013 at 2:40 pm
demonfox (4/11/2013)
Primo Dang (4/11/2013)
Got it right by eliminationThanks, Sasidhar Pulivarthi! 😀
+1
Thanks for the question ..
+1
Thanks
April 12, 2013 at 3:56 pm
What I find annoying is that by assigning a value of '' to the Datetime2 variable is that it has gone for '1900........'
My preference would be to set the variable to its lowest possible value which is '0001-01-01..........'
I guess that Microsoft has gone for consistency ?
David
April 12, 2013 at 8:06 pm
+1..
Thanks for the question..
April 14, 2013 at 1:52 pm
Thanks for the question.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
April 17, 2013 at 8:39 am
David Conn (4/12/2013)
What I find annoying is that by assigning a value of '' to the Datetime2 variable is that it has gone for '1900........'My preference would be to set the variable to its lowest possible value which is '0001-01-01..........'
I guess that Microsoft has gone for consistency ?
David
The default value is equivalent to zero, at least for the older datatypes, DateTime and SmallDateTime, and zero is defined to be 1900-01-01. Older dates are therefore "negative numbers". I tried to modify the question to set the 4 variables = 0, but learned that this is not allowed for the newer DateTime2 and Date datatypes (even with an explicit conversion) (at least, in SQL 2008).
Msg 529, Level 16, State 2, Line 6
Explicit conversion from data type numeric to date is not allowed.
So, to demonstrate the zeros, I ended up with:
Declare @smldatetime SmallDateTime
, @dt DateTime
, @dt2 DateTime2
, @d Date
Select
@d=''
, @smldatetime=0
, @dt=0
, @dt2 =''
Select
CAST(@d as varchar)
, CAST(@smldatetime as VARCHAR)
, CAST(@dt as VARCHAR)
, CONVERT(varchar,@dt2 )
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply