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,

3
  • 3
    Possible duplicate of Convert one date format into another in PHP Commented Jul 8, 2016 at 9:34
  • Why you add .""); to $vehicle->newDate? Commented Jul 8, 2016 at 9:34
  • @Saty removed it was unnecessary Commented Jul 8, 2016 at 9:37

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

5 Comments

$vehicle->newDate="Sat Oct 04 00:00:00 GMT+05:30 2008" then why my code is having problem ? Can you explain please
if you code pass invalid date, php date function will show you 1970-01-01 05:30:00.
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).
$lsd = strtotime($vehicle->newDate); then echo $lsd doen't show anything, that means that your $lsd variable is overwrite.
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 :)
0

Try this

$lsd = strtotime($vehicle->newDate);
$newDate = date("D M j G:i:s T Y");

2 Comments

You might want to add $lsd to the date() function and what is ."" supposed to achieve
Sorry buddy! i just pasted his code with some modification!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.