Re: Another date exercise

From: Date: Wed, 19 Aug 2009 21:12:59 +0000
Subject: Re: Another date exercise
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-296984@lists.php.net to get a copy of this message
At 10:43 AM -0500 8/19/09, Shawn McKenzie wrote:
First stab at it. Of course it needs US date ordering (month day year).
You can't do euro type dates or any other format because there is no way to tell the difference between 1/2/2009 (January) and 1/2/2009 (February): <?php $dates = array( 'August 5, 2009', 'Aug 05 2009', 'Aug 5, 9', '08/05/09', '8-5-9', '8 05 2009', '8,5,9',); foreach($dates as $date) {
     $date = preg_replace("#([\d])+[^/\d]+([\d]+)[^/\d]+([\d]+)#",
"$1/$2/$3", $date);
     echo date("M j, Y", strtotime($date)) ."\n";
} ?>
Guess you didn't like this one? Also, if you change the / to - in the preg_replace() it should work on Euro style dates. $date = preg_replace("#([\d])+[^-\d]+([\d]+)[^-\d]+([\d]+)#", "$1-$2-$3", $date); -Shawn
-Shawn: Thanks, but my idea was more along the lines of this: http://php1.net/b/date-picker/index.php It's not thoroughly tested, but thus far it works. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com

« previous php.general (#296984) next »