savagenoob Posted January 5, 2009 Share Posted January 5, 2009 How would I change a date in this (01/01/2009) format to (2009-01-01)? Link to comment https://forums.phpfreaks.com/topic/139581-solved-changing-dates/ Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 strtotime then date or explode $date = "01/01/2009"; $date = explode("/", $date); $newDate = $date[2] . "-" . $date[1] . "-" . $date[0]; $date = "01/01/2009"; $date = strtotime($date); $newDate = date('Y-m-d', $date); echo $newDate; Link to comment https://forums.phpfreaks.com/topic/139581-solved-changing-dates/#findComment-730185 Share on other sites More sharing options...
Maq Posted January 5, 2009 Share Posted January 5, 2009 Like this: $date = "01/01/2009"; $output = date("Y-m-d, strtotime($date)); echo $output; premiso stop posting before me!!!! Link to comment https://forums.phpfreaks.com/topic/139581-solved-changing-dates/#findComment-730188 Share on other sites More sharing options...
premiso Posted January 5, 2009 Share Posted January 5, 2009 Like this: $date = "01/01/2009"; $output = date("Y-m-d, strtotime($date)); echo $output; premiso stop posting before me!!!! =) Link to comment https://forums.phpfreaks.com/topic/139581-solved-changing-dates/#findComment-730189 Share on other sites More sharing options...
savagenoob Posted January 5, 2009 Author Share Posted January 5, 2009 Thanks guys... Link to comment https://forums.phpfreaks.com/topic/139581-solved-changing-dates/#findComment-730205 Share on other sites More sharing options...
PFMaBiSmAd Posted January 5, 2009 Share Posted January 5, 2009 The explode/concatenate method (when you are just rearranging the order of existing fields) is 8 times faster than date/strtotime and it has an added advantages that in the exploded form you can validate the date using checkdate and you can use the explode method with formats don't work with strtotime. Link to comment https://forums.phpfreaks.com/topic/139581-solved-changing-dates/#findComment-730213 Share on other sites More sharing options...
Maq Posted January 5, 2009 Share Posted January 5, 2009 The explode/concatenate method (when you are just rearranging the order of existing fields) is 8 times faster than date/strtotime and it has an added advantage that in the exploded form you can validate the date using checkdate Heh, didn't know that, thanks PFMaBiSmAd! Link to comment https://forums.phpfreaks.com/topic/139581-solved-changing-dates/#findComment-730216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.