Re: Another date exercise

From: Date: Mon, 17 Aug 2009 17:15:17 +0000
Subject: Re: Another date exercise
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-296890@lists.php.net to get a copy of this message
tedd wrote: > At 3:40 PM +0530 8/17/09, kranthi wrote: >> dont you think http://in3.php.net/strtotime is a solution >> to your >> problem ? > > No, it's not a solution to my problem -- I have he problem solved. > > I was just asking if anyone wanted to submit their php solution. It was > only an exercise. > > I know there are numerous javascript solutions (some good, some bad), > but ALL of their data has to be accepted and scrubbed by a php script > anyway, so I was suggesting creating a php script to do it. > > If it's not a good exercise, then don't do it. 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"; } ?> -- Thanks! -Shawn http://www.spidean.com

« previous php.general (#296890) next »