ainoy31 Posted October 26, 2007 Share Posted October 26, 2007 Hello- I am trying to convert from a 4-digit to a 2-digit year. Here is my code: $date = "2007-10-02"; $explode_date = explode("-", $date); echo $new_date = $explode_date[1].$explode_date[2].$explode_date[0]; The result is 10022007 but I need it to be 100207(mmddyy). Any suggestion is much appreciated. AM Link to comment https://forums.phpfreaks.com/topic/74923-solved-convert-from-4-digit-to-2-digit-year/ Share on other sites More sharing options...
premiso Posted October 26, 2007 Share Posted October 26, 2007 <?php $date = "2007-10-02"; $timestamp = strtotime($date); $new_date = date("mdy", $timestamp); ?> www.php.net/date www.php.net/strtotime Link to comment https://forums.phpfreaks.com/topic/74923-solved-convert-from-4-digit-to-2-digit-year/#findComment-378852 Share on other sites More sharing options...
sasa Posted October 26, 2007 Share Posted October 26, 2007 or echo $new_date = $explode_date[1].$explode_date[2].$explode_date[0] % 100;echo $new_date = $explode_date[1].$explode_date[2].substr($explode_date[0],-2); Link to comment https://forums.phpfreaks.com/topic/74923-solved-convert-from-4-digit-to-2-digit-year/#findComment-378857 Share on other sites More sharing options...
ainoy31 Posted October 26, 2007 Author Share Posted October 26, 2007 Thanks man. I overlooked the strtotime... Link to comment https://forums.phpfreaks.com/topic/74923-solved-convert-from-4-digit-to-2-digit-year/#findComment-378878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.