0

Hi I want change date string -> Sat Oct 04 00:00:00 GMT+05:30 2008 -> into 'Y-m-d H:i:s' format my code is as below :

$lsd = strtotime($vehicle->newDate);
$newDate = date('Y-m-d H:i:s',$lsd);

I am getting date like 1970-01-01 05:30:00 Why is so ?

I have gone through reference : http://php.net/manual/en/function.date.php

I have got date fromat representation labels for all except GMT+05:30

   Sat Oct 04 00:00:00 GMT+05:30 2008
   D    M   d   H:i:s            o

Instead of down-votes if that one label I get then I will be thankful then I will use http://php.net/manual/en/datetime.format.php,

Prashant
  • 4,474
  • 8
  • 34
  • 82

2 Answers2

2

Use this one.

$lsd = strtotime("Sat Oct 04 00:00:00 GMT+05:30 2008");
$newDate = date('Y-m-d H:i:s',$lsd);
echo $newDate;
Hardik
  • 448
  • 2
  • 9
  • $vehicle->newDate="Sat Oct 04 00:00:00 GMT+05:30 2008" then why my code is having problem ? Can you explain please – Prashant Jul 08 '16 at 09:56
  • if you code pass invalid date, php date function will show you 1970-01-01 05:30:00. – Hardik Jul 08 '16 at 10:07
  • after giving echo $vehicle->newDate has value = "Wed Dec 16 00:00:00 GMT 05:30 2015" but after $lsd = strtotime($vehicle->newDate); then echo $lsd doen't show anything, hence date('Y-m-d H:i:s',$lsd); might be returning the default (date from beginning). – Prashant Jul 08 '16 at 10:21
  • $lsd = strtotime($vehicle->newDate); then echo $lsd doen't show anything, that means that your $lsd variable is overwrite. – Hardik Jul 08 '16 at 10:25
  • Problem was @server coz "Sat Oct 04 00:00:00 GMT+05:30 2008" was not url safe parameter hence while reading due to '+' sign in "GMT+05:30" it was parsed as space like "Sat Oct 04 00:00:00 GMT 05:30 2008" hence strtotime() was failing,corrected from server started working thank you for your help :) – Prashant Jul 08 '16 at 10:49
0

Try this

$lsd = strtotime($vehicle->newDate);
$newDate = date("D M j G:i:s T Y");
Aniruddha Chakraborty
  • 1,849
  • 1
  • 20
  • 32