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


Dating for DBAs - a second date


Dating for DBAs - a second date

Author
Message
mtassin
mtassin
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13388 Visits: 72528
Duncan Pryde (4/13/2011)
Henrico Bekker (4/12/2011)
All 4 options work? one of those questions again...pick 2 out of 4 correct answers...a quessing game again.


Try this:

SET DATEFORMAT ydm
GO
SELECT CAST('2011-04-28' AS DATETIME)



or this:

SET LANGUAGE British
GO
SELECT CAST('2011-04-28' AS DATETIME)



and do the same for the other date types, and you'll see that DATETIME and SMALLDATETIME produce an error while DATE and DATETIME2 don't.

So no guessing required!

Duncan


Just look up the various data types in books online.

Only DATE and DATETIME2 have Default String literals... the others do not. And the default string literals are YYYY-MM-DD Smile



--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
Andre Guerreiro
Andre Guerreiro
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4207 Visits: 1517
Fortunately I got it right because I somehow knew it'd be a tricky question and I'm studying the new data types in MSSQL 2008. :-D

But I've never tested them that way and I see a lot of errors when dealing with datetime/smalldatetime conversion to other data types around the internet.

Hoepfully those new date and time types will make our lives easier.

Thank you for the question. Smile

Best regards,

Best regards,

Andre Guerreiro Neto

Database Analyst
http://www.softplan.com.br
MCITPx1/MCTSx2/MCSE/MCSA
dennisp
dennisp
SSChasing Mays
SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)

Group: General Forum Members
Points: 654 Visits: 129
All 4 work on my SQL 2008.
bogus question...

Dennis Parks
MCSE, MCDBA, MCSD, MCAD, MCTS
SanDroid
SanDroid
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4672 Visits: 1046
dennisparks (4/19/2011)
All 4 work on my SQL 2008.
bogus question...

Really?!?!

Try running either
SET DATEFORMAT ydm
or
SET LANGUAGE British

and then see what your results are.

Like someone already pointed out BOL states that DATE and DATETIME2 have Default String literals of YYYY-MM-DD the others do not.
dennisp
dennisp
SSChasing Mays
SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)

Group: General Forum Members
Points: 654 Visits: 129
I don't remember the question stating to change the default date setting.
under default settings, they work fine.

Dennis Parks
MCSE, MCDBA, MCSD, MCAD, MCTS
Cliff Jones
Cliff Jones
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6835 Visits: 3648
dennisparks (4/19/2011)
I don't remember the question stating to change the default date setting.
under default settings, they work fine.


The question clearly stated which ones work 'regardless of any date format or language settings?'.
dennisp
dennisp
SSChasing Mays
SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)SSChasing Mays (654 reputation)

Group: General Forum Members
Points: 654 Visits: 129
ok, then I guess it tricked me. :~)

Dennis Parks
MCSE, MCDBA, MCSD, MCAD, MCTS
Mr Quillz
Mr Quillz
SSC-Enthusiastic
SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)SSC-Enthusiastic (173 reputation)

Group: General Forum Members
Points: 173 Visits: 240
Something is wrong with that answer provided.
paul.knibbs
paul.knibbs
SSCrazy Eights
SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)

Group: General Forum Members
Points: 8028 Visits: 6240
Mr Quillz (5/13/2011)
Something is wrong with that answer provided.


No, there isn't. Try reading the rest of the thread.
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