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 Link to comment https://forums.phpfreaks.com/topic/190074-format-a-date-in-_posttransdate-as-14011970-to-1970-01-14-format/ 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])); ?> Link to comment https://forums.phpfreaks.com/topic/190074-format-a-date-in-_posttransdate-as-14011970-to-1970-01-14-format/#findComment-1002850 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 Link to comment https://forums.phpfreaks.com/topic/190074-format-a-date-in-_posttransdate-as-14011970-to-1970-01-14-format/#findComment-1002853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.