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


datetime


datetime

Author
Message
vasanthlal.va
vasanthlal.va
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 6
Hi experts,
Why below statement giving the error and not considering as datetime.Please advise.

Msg 242, Level 16, State 3, Line 1
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.


declare @snapshotdate datetime='24-03-2016 00:00:00'
select isdate('24-03-2016 00:00:00') -- This is giving as 0
Regards
Vasanthlal
GilaMonster
GilaMonster
SSC Guru
SSC Guru (902K reputation)SSC Guru (902K reputation)SSC Guru (902K reputation)SSC Guru (902K reputation)SSC Guru (902K reputation)SSC Guru (902K reputation)SSC Guru (902K reputation)SSC Guru (902K reputation)

Group: General Forum Members
Points: 902794 Visits: 48740
It's defaulting to the American format, month/day/year, hence you're trying to convert the 3rd day of the 24th month, which doesn't exist.

Use unambiguous formats (preferred), or use CONVERT with a format code.
declare @snapshotdate datetime='2016-03-24 00:00:00'
select isdate(@snapshotdate)


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


vasanthlal.va
vasanthlal.va
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 6
Thank you Smile
shwetakakran01
shwetakakran01
SSC Journeyman
SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)SSC Journeyman (82 reputation)

Group: General Forum Members
Points: 82 Visits: 12
your date format is not correct. it should be month/date/year. your are trying to do with date/month/year which is not correct according to format.
Jason A. Long
Jason A. Long
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19376 Visits: 7592
shwetakakran01 - Wednesday, February 7, 2018 4:58 AM
your date format is not correct. it should be month/date/year. your are trying to do with date/month/year which is not correct according to format.

Who's format? day-month-year is actually a very common format in Europe. The problem isn't the format per se. As Gail pointed out, the problem is the format in conjunction with the regional settings... That or use the universal YYYY-MM-DD HH:mm:SS or YYYYMMDD formats.

If the OP is stuck having to deal with the DD-MM-YYYY... format, the CONVERT or TRY_CONVERT functions can be an easy fix...

SELECT CONVERT(DATETIME, '24-03-2016 00:00:00', 103);
-- or
SELECT ISDATE(CONVERT(DATETIME, '24-03-2016 00:00:00', 103));

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