note 532 deleted from function.checkdate by jimw

From: Date: Fri, 07 Dec 2001 20:37:26 +0000
Subject: note 532 deleted from function.checkdate by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-21938@lists.php.net to get a copy of this message
Tip: mySQL for example, has very good date-routines. It eats nearly every kind of date correctly. So if you use a DB, it is not so a bad idea to use the routines from it, cause the routines in the DB also can correct the year. This trick can ship you around problems with Y2K. You can do for example: $formdate="28.01.99"; # comes normally from your input form, her e.g. german date # This lines splits it up: one or more digits, seperated by non-digits $mydate=ereg("([[:digit:]]+)[^[:digit:]]([[:digit:]]+)[^[:digit:]]([[:digit:]]{2,4})",$fromdate,$regs); $newdate="$regs[3]-$regs[2]-$regs[1]"; # date is now "99-01-28" $r=mysql("BLA_DB","SELECT UNIX_TIMESTAMP('$newdate') as d"); if ($d=mysql_result($r,0,"d")>0) { # Date is correct echo Date("d.m.Y",$d); # will show now 28.01.1999 # remark, that mySQL assumes, that years < 70 or so are in year 2000 and up }

« previous php.notes (#21938) next »