PHP Tutorials

Howto detect if typed date is valid

This simple tip allow you to detect if the date is typed correctly and the date format is as expected.

6 risposte su “Howto detect if typed date is valid”

Riddle: catch the bug.

isValidDate('30/08/2012', '/', 'dmy') == true
isValidDate('29/02/2000', '/', 'dmy') == true
isValidDate('10/10/1580', '/', 'dmy') == true
isValidDate('29/02/2001', '/', 'dmy') == false
isValidDate('10/10/1582', '/', 'dmy') == true
isValidDate('10/12/2121', '/', 'dmy') == true
isValidDate('10/10/2000', '/', 'dmy') == true

where is the function lack?

Hi Giacomo,
trying the following code:

Hi Giacomo,
trying the following code:

var_dump(validaData('30/08/2012', '/', 'dmy')); # bool(true)
var_dump(validaData('29/02/2000', '/', 'dmy')); # bool(true)
var_dump(validaData('10/10/1580', '/', 'dmy')); # bool(true)
var_dump(validaData('29/02/2001', '/', 'dmy')); # bool(false)
var_dump(validaData('10/10/1582', '/', 'dmy')); # bool(true)
var_dump(validaData('10/12/2121', '/', 'dmy')); # bool(true)
var_dump(validaData('10/10/2000', '/', 'dmy')); # bool(true) 

the output is as expected. So… where is the bug? :)

no, it wasn’t!
the day after 4th october, was 15th october, according to Gregorian calendar.

….but ….

…but…. there are many consideration we could do. (i.e. Swedish Reign used Giulian (Assange) calendar till 1699)

I commenti sono chiusi