SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Date Puzzle


Date Puzzle

Author
Message
Toreador
Toreador
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2793 Visits: 8084
Hugo Kornelis (10/27/2010)
For the datetime data type, The only formats that are guaranteed to work correctly in all circumstances are:
* yyyymmdd - for dates without time portion. No dashes. dots, slashes or other punctuation. The resulting datetime value will have its time portion set to midnight.


We use yyyy-mm-dd which has always worked so far.
Should I be worried?!
DugyC
DugyC
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1426 Visits: 779
I'm absolutely gob smacked somebody answered 29Apr, or even worse 31Mar. Ermm

I'll give them the benefit of the doubt though and presume they suspected a trick question. :-D

Agree with the previous poster that 30Apr, 31Apr, 1May would have been more teasing options.

Good question though, I like the easy ones... coz I can answer those :-P

_____________________________________________________________________
"The difficult tasks we do immediately, the impossible takes a little longer"
Hugo Kornelis
Hugo Kornelis
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11092 Visits: 12001
Toreador (10/27/2010)
Hugo Kornelis (10/27/2010)
For the datetime data type, The only formats that are guaranteed to work correctly in all circumstances are:
* yyyymmdd - for dates without time portion. No dashes. dots, slashes or other punctuation. The resulting datetime value will have its time portion set to midnight.


We use yyyy-mm-dd which has always worked so far.
Should I be worried?!

set language German;
select cast('2010-10-27' as datetime);
select cast('20101027' as datetime);


Die Spracheneinstellung wurde auf Deutsch geändert.

-----------------------
Msg 242, Level 16, State 3, Line 2
Bei der Konvertierung eines char-Datentyps in einen datetime-Datentyp liegt der datetime-Wert außerhalb des gültigen Bereichs.


-----------------------
2010-10-27 00:00:00.000


German was the first of the languages I tested that returned an error when using yyyy-mm-dd. I did not try the remaining languages. You can easily do that for yourself.
(For a list of possible languages, run "select * from sys.syslanguages;", and use either the "name" or the "alias" column as argument for SET LANGUAGE).


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
pravin wagh
pravin wagh
SSC-Enthusiastic
SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)

Group: General Forum Members
Points: 135 Visits: 381
easy question
SanDroid
SanDroid
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1580 Visits: 1046
I give this question Five Stars!

It was code correct, the question was clear and had no typo's, and the author clearly understood the concept his question was testing.

This Question of the Day has been plagued lately with poorly worded and misspelled code examples and questions. That along with the fact they they were complex questions with complex SQL Server features and statements made them horible.
Toreador
Toreador
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2793 Visits: 8084
Fortuntely I was fibbing and we actually convert to proper dates before passing to SQLServer :-)
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27597 Visits: 13268
SanDroid (10/27/2010)
I give this question Five Stars!

It was code correct, the question was clear and had no typo's, and the author clearly understood the concept his question was testing.

This Question of the Day has been plagued lately with poorly worded and misspelled code examples and questions. That along with the fact they they were complex questions with complex SQL Server features and statements made them horible.


All I am reading is: easy question = good, difficult question = bad ;-)


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
paul.knibbs
paul.knibbs
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2573 Visits: 6232
DougieCow (10/27/2010)
I'm absolutely gob smacked somebody answered 29Apr, or even worse 31Mar. Ermm


I'm kind of baffled anyone would have picked 29-Apr too--there's actually some logic to picking 31-Mar, but 29th April? Blink
SanDroid
SanDroid
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1580 Visits: 1046
da-zero (10/27/2010)

All I am reading is: easy question = good, difficult question = bad ;-)


I can tell by your reading and writing level you might be the moderator checking the questions before posting them.
Suggestion, actually try to execute the code and check for errors. This is the first QOTD I have looked at this month that didn't have any.

Is that easy or difficult for you to understand? Cool
Hugo Kornelis
Hugo Kornelis
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11092 Visits: 12001
SanDroid (10/27/2010)
da-zero (10/27/2010)

All I am reading is: easy question = good, difficult question = bad ;-)


I can tell by your reading and writing level you might be the moderator checking the questions before posting them.
Suggestion, actually try to execute the code and check for errors. This is the first QOTD I have looked at this month that didn't have any.

Is that easy or difficult for you to understand? Cool

The only people who review the questions are the question author (Abhijit for this question), and Steve Jones. And Steve often lacks the time to properly check the questions. So your assessment of da-zero is wrong.

I do not agree with the comment da-zero made to your post. But I also disagree with your enthousiasm about this question. I do agree partly with the second sentence you wrote ("It was code correct, the question was clear and had no typo's, and the author clearly understood the concept his question was testing"), though the code was definitely not safe in non-US environments.

But I totally disagree with your final statement ("That along with the fact they they were complex questions with complex SQL Server features and statements made them horible"). These questions should provide a learning opportunity, and that will hardly happen with questions as simple as this one. I expect the QotD to be about complex and/or little-known features.
(And yes, I also expect them to be error-free -which unfortunately happens less often than I would like).


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search