0

I have a date in php in the format as Tue Jun 16 2015 05:30:00 GMT 0530 (India Standard Time)

I want to convert it in format mm-DD-YYYY

How can I do it ?

I have tried to use

$old_date_timestamp = strtotime($curddat);
echo $new_date = date('Y-m-d H:i:s', $old_date_timestamp);

but it is giving result

1970-01-01 00:00:00

While the value of $curddat is Tue Jun 16 2015 05:30:00 GMT 0530 (India Standard Time)

Rohitashv Singhal
  • 4,517
  • 13
  • 57
  • 105

2 Answers2

1
echo $old_date_timestamp = strtotime('Tue Jun 16 2015 05:30:00'); //GMT 0530 (India Standard Time) not needed
echo $new_date = date('Y-m-d H:i:s', $old_date_timestamp);

//output 2015-06-16 05:30:00
Dimag Kharab
  • 4,439
  • 1
  • 24
  • 45
0

strtotime can't convert your string to data when you have extra India Standard Time and so on. Just remove that:

$curddat = 'Tue Jun 16 2015 05:30:00 GMT 0530 (India Standard Time)';
$curddat = str_replace(' GMT 0530 (India Standard Time)','',$curddat);

$old_date_timestamp = strtotime($curddat);
echo $new_date = date('m-d-Y', $old_date_timestamp);
Muhammet
  • 3,288
  • 13
  • 23