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)? Quote Link to comment 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; Quote Link to comment 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!!!! Quote Link to comment 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!!!! =) Quote Link to comment Share on other sites More sharing options...
savagenoob Posted January 5, 2009 Author Share Posted January 5, 2009 Thanks guys... Quote Link to comment 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. Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.