cancel
Showing results for 
Search instead for 
Did you mean: 

IsDate() returns true for invalid date

1,530

If I run select Isdate('20190001'); I get 1 (true) I have tried running with SET TEMPORARY OPTION DATE_ORDER = 'YMD'; and it still returns true

If I run select ymd(2019, 00, 01); I get 2018-12-01 which indicates 2019, 00, 01 is not a valid date!

following example here http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1520/html/iqrefbb/I...

select Isdate('2019/00/01'); Still returns true

select Isdate('2019/01/00') correctly returns false

VolkerBarth
Contributor
0 Kudos

Is your question (which you posted as an answer, BTW) related to the above question and to SQL Anywhere?

MarkCulp
Participant
0 Kudos

AFAIK SQL Anywhere does not have an "isValid" function so this must be a question about some other product. What product is unknown? ... by the syntax used I might guess javascript's moment.js?

Accepted Solutions (0)

Answers (2)

Answers (2)

MarkCulp
Participant

As Breck has pointed out, there is a change of behaviour in the isdate() and cast( ... as date ) functions in v17 and it is a bug. This will be fixed.

However, YMD() is functioning as expected. The v17 documentation (also v10, v11, etc) states that the year is adjusted if the month is out of range. (Note: the doc does not actually state how it is adjusted... that is left to the reader to figure out ;-)). The date is also adjusted accordingly if the day is out of range.

HTH

jack_schueler
Advisor
Advisor

Did we forget to document the new "I know you meant 01 instead of 00 feature in version 17"? Oh well, it'll be fixed.

Breck_Carter
Participant

> there is a change of behaviour

That's not a behavior change.

THIS is a behavior change...

Breck_Carter
Participant

It's a bug in Version 17...

SELECT @@VERSION, ISDATE('2019-00-01');

@@VERSION,ISDATE('2019-00-01')
'9.0.2.2451',0

@@VERSION,ISDATE('2019-00-01')
'10.0.1.4310',0

@@VERSION,ISDATE('2019-00-01')
'11.0.1.3158',0

@@VERSION,ISDATE('2019-00-01')
'12.0.1.4231',0

@@VERSION,ISDATE('2019-00-01')
'16.0.0.2512',0

@@VERSION,ISDATE('2019-00-01')
'17.0.9.4882',1

0 Kudos

Thanks Breck for your speedy response

0 Kudos

Workaround

Compare(Dateformat(YMD(Substr(20190001, 1, 4), Substr(20190001, 5, 2), Substr(20190001,7, 2)), 'YYYYMMDD'), 20190001)

<> 0 --Invalid date

= 0 -- Valid date