change date format in using php
I am trying to change the date format dd/mm/yy Ex:25/08/2013 to yyyy-mm-dd
Ex:2013-08-25 using PHP
I have tried in below ways
//Method 1:
$olddate="25/08/2013";
$originalDate = "$olddate";
$newdate = date("Y-m-d", strtotime($originalDate));
//Result : 1970-01-01
//Method 2 :
$olddate="25/08/2013";
preg_match_all('/(\d+)-(\d+)-(\d+)-(\d+)-(\d+)-(\d+)/', $old_date, $out,
PREG_SET_ORDER);
$out = $out[0];
$time = mktime($out[4], $out[5], $out[6], $out[2], $out[3], $out[1]);
$new_date = date('Y-m-d', $time);
//Result : 1999-03-11
//Method 3 :
$olddate="25/08/2013";
$date = DateTime::createFromFormat('dd/mm/yy', $olddate);
$newdate=$date->format('Y-m-d');
//Result:no result
But i am not getting the expected output.
Please give me suggestions or let me know if i am doing any mistake.
Thanks in advance,
Sowmya
No comments:
Post a Comment