note 52739 deleted from function.strtotime by derick

From: Date: Sun, 15 Jul 2007 12:48:15 +0000
Subject: note 52739 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-128582@lists.php.net to get a copy of this message
Note Submitter: Rene Leonhardt (rele at gmx dot de) ---- Here is a slightly improved version of date_uk_to_american, posted by James McGuigan on 27-Dec-2004 08:31. Now you can use the function to parse a date string (user input) to show, whether it was recognized correctly. function date_uk_to_american($date, $replace_separator = FALSE) { $days = '0?[1-9]|[12][0-9]|3[01]'; $months= '0?[1-9]|1[0-2]'; $year = '\d{2}|\d{4}'; $non_alpha = '[^0-9a-zA-Z]+'; return preg_replace( "/^\s*($days)($non_alpha)($months)($non_alpha)($year)/", $replace_separator === FALSE ? '$3$2$1$4$5' : '$3'.$replace_separator.'$1'.$replace_separator.'$5', $date); } function parse_date($date) { return date("d.m.Y", strtotime(date_uk_to_american($date, '/'))); } //example: echo parse_date('3.12.83');

« previous php.notes (#128582) next »