note 95839 added to function.checkdate

From: Date: Mon, 25 Jan 2010 10:20:41 +0000
Subject: note 95839 added to function.checkdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-165266@lists.php.net to get a copy of this message
<?php // my current timezone is CET var_dump(Check::date('1.12.2010')); // int(1291161600) var_dump(Check::date('2010-12-1')); // int(1291161600) var_dump(Check::date('20101201')); // int(1291161600) var_dump(Check::date('12/01/2010'));// int(1291161600) var_dump(Check::date('29.2.2009')); // bool(false) var_dump(Check::date('2009-2-29')); // bool(false) var_dump(Check::date('20100229')); // bool(false) var_dump(Check::date('2/29/2009')); // bool(false) class Check { public static function date($date) { // jjjj-m-d $r1='/^(20[012][0-9])-([0-9]|0[0-9]|1[012])-([0-9]|'. '[012][0-9]|3[01])$/S'; // jjjjmmdd / jjjj-mm-dd $r2='/^(20[012][0-9])(-|)(0[0-9]|1[012])(-|)([012]'. '[0-9]|3[01])$/S'; // d.m.jjjj $r3='/^([0-9]|[012][0-9]|3[013])\.([0-9]|[012][0-9]'. '|3[01])\.(20[012][0-9])$/S'; // m/d/jjjj $r4='/^([0-9]|[012][0-9]|3[01])\/([0-9]|[012][0-9]|'. '3[013])\/(20[012][0-9])$/S'; // remove the '. ' if(preg_match($r1,$date,$e) && checkdate($e[2],$e[3],$e[1])) return mktime(0,0,0,$e[2],$e[3],$e[1]); if(preg_match($r2,$date,$e) && checkdate($e[3],$e[5],$e[1])) return mktime(0,0,0,$e[3],$e[5],$e[1]); if(preg_match($r3,$date,$e) && checkdate($e[2],$e[1],$e[3])) return mktime(0,0,0,$e[2],$e[1],$e[3]); if(preg_match($r4,$date,$e) && checkdate($e[1],$e[2],$e[3])) return mktime(0,0,0,$e[1],$e[2],$e[3]); return false; } public static function time($time) { // h:i $r1='/^([0-9]|[01][0-9]|2[0-3]):([0-9]|'. '[0-5][0-9])$/S'; // hh:ii / hhii $r2='/^([01][0-9]|2[0-3])(:|)([0-5][0-9]'. ')$/S'; // h:i:s $r3='/^([0-9]|[01][0-9]|2[0-3]):([0-9]|[0-5]'. '[0-9]):([0-9]|[0-5][0-9])$/S'; // hh:ii:ss / hhiiss $r4='/^([01][0-9]|2[0-3])(:|)([0-5][0-9])(:|)'. '([0-5][0-9])$/S'; // remove the '. ' if(preg_match($r1,$time,$e)) return ((int)$e[1]*3600) + ((int)$e[2]*60); if(preg_match($r2,$time,$e)) return ((int)$e[1]*3600) + ((int)$e[3]*60); if(preg_match($r3,$time,$e)) return ((int)$e[1]*3600) + ((int)$e[2]*60)+(int)$e[3]; if(preg_match($r4,$time,$e)) return ((int)$e[1]*3600) + ((int)$e[3]*60)+(int)$e[5]; return false; } } ?> ---- Server IP: 85.214.154.209 Probable Submitter: 217.9.60.197 ---- Manual Page -- http://www.php.net/manual/en/function.checkdate.php Edit -- https://master.php.net/note/edit/95839 Del: integrated -- https://master.php.net/note/delete/95839/integrated Del: useless -- https://master.php.net/note/delete/95839/useless Del: bad code -- https://master.php.net/note/delete/95839/bad+code Del: spam -- https://master.php.net/note/delete/95839/spam Del: non-english -- https://master.php.net/note/delete/95839/non-english Del: in docs -- https://master.php.net/note/delete/95839/in+docs Del: other reasons-- https://master.php.net/note/delete/95839 Reject -- https://master.php.net/note/reject/95839 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165266) next »