-1

I have a date in this formatThu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time) and I want to convert this in to PHP date format Y-m-d

Code is as follows

$statMonth = 'Thu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time)'
echo date('Y-m', strtotime($statMonth));

returns me 1970-01

Can you please let me know how to get Month and Year.

Kiran Kumar
  • 181
  • 1
  • 4
  • 13

1 Answers1

0

You need to remove (India Standard Time) from your date, You can use following regex to remove dynamically:

$statMonth = 'Thu Oct 15 2015 12:51:49 GMT+0530 (India Standard Time)';
$statMonth = trim(preg_replace('/\s*\([^)]*\)/', '', $statMonth));
echo date('Y-m', strtotime($statMonth));
Muhammad Bilal
  • 2,106
  • 1
  • 15
  • 24
  • it worked like charm, what about if preg_replace is deprecated in future.. is there a way we can do it via only date format – Kiran Kumar Oct 15 '15 at 09:40