date(n/Y) strtotime

From: Date: Wed, 02 Aug 2006 15:46:34 +0000
Subject: date(n/Y) strtotime
Groups: php.general 
Request: Send a blank email to php-general+get-240006@lists.php.net to get a copy of this message
I've always been really amazed at how well strtotime works, but recently ran into an issue where it couldn't figure out the date if it was a cc exp date in long format, e.g. 1/2009. I was curious if anyone else has run into this and how did they get around it, here was my solution: function expDate2str( $date ) { if( !($sDate = strtotime( $date ) ) ) { // exploded date $eDate = explode( '/', $date ); // string date we hard code the day to 1 $sDate = strtotime( date( "Y-m-d", mktime( 0, 0, 0, $eDate[0], 1, $eDate[1] ) ) ); } return $sDate; } Thanks, Mark -------------------------------------------------------------- Mark Steudel Web Applications Developer 555 Dayton St Suite A Edmonds, WA 98020 p: 425.741.7014 e: mark@netriver.net w: http://www.netriver.net

« previous php.general (#240006) next »