Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Teaser (string to date conversion) 1

Status
Not open for further replies.

gmmastros

Programmer
Joined
Feb 15, 2005
Messages
14,912
Location
US
Without running this, what do you think the output is?

Code:
[COLOR=blue]Set[/color] [COLOR=#FF00FF]DATEFORMAT[/color] DMY
[COLOR=blue]Select[/color] [COLOR=#FF00FF]Convert[/color]([COLOR=#FF00FF]DateTime[/color], [COLOR=red]'100205'[/color])

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
I was wrong just for the books

____________ signature below ______________
You may get help by means of code here. Just recall what happens to a rat when he eats the cheese off a rat trap while you're Ctrl+C/Ctrl+V'ing that code as your own

 
Let me try

02-10-2005 00:00:00.000 ???

[monkey][snake] <.
 
Nope. Try again.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
2005-02-10 00:00:00.000

Last try, then I cheat.

[monkey][snake] <.
 
Nope but if it makes you feel better one of your guesses is about the same as mine

____________ signature below ______________
You may get help by means of code here. Just recall what happens to a rat when he eats the cheese off a rat trap while you're Ctrl+C/Ctrl+V'ing that code as your own

 
My guess:
2005-02-10 00:00:00

-SQLBill

Posting advice: FAQ481-4875
 
Shoot - tested it and I got it wrong. Now I'm waiting for the explanation of why it happens that way.

-SQLBill

Posting advice: FAQ481-4875
 
The SET DATEFORMAT session setting does not apply to all-numeric date entries such as numeric entries without separators. The 6-digit or 8-digit strings are always interpreted as ymd. The month and day must always be 2 digits.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
My guess would be an out of range date?

- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
Hmmm,
Well, I was wrong about that one!



- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
My try

02 oct 2005 12:00AM


Well Done is better than well said
- Ben Franklin
 
fredericofonseca was completely right. If I had said, "What is the output?" for Select Convert(DateTime, '20100205'), I suspect that most of you would have gotten it correct. Feb 5, 2010.

Since there were only six digits, and I put a Set DATEFORMAT in the code, it threw you all off.

When there are only six digits, SQL Server will use the Cutoff Date for century (50 and above is 1950, 49 and below is 2049).

Star to Frederico for the first to post the correct answer.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top