csplrj Posted January 28, 2010 Share Posted January 28, 2010 The date I receive is in dd/mm/yyyy format. I want to convert it into yyyy-mm-dd format How to format a date which i get from user in $_POST['transdate'] as 14/01/1970 to 1970-01-14 format? Thanks in advance CSJakharia Quote Link to comment Share on other sites More sharing options...
mapleleaf Posted January 28, 2010 Share Posted January 28, 2010 <?php //$_POST['transdate'] replaces the date in the explode $date = explode('/','14/01/1970'); echo date("Y-m-d", mktime(0, 0, 0, $date[1], $date[0], $date[2])); ?> Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 28, 2010 Share Posted January 28, 2010 Another way $date = '14/01/1970'; $date = preg_replace('%(\d{2})/(\d{2})/(\d{4})%' , "\\3-\\2-\\1" , $date); HTH Teamatomic 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.