0

From server I get this value: 2014-07-02T05:13:45Z I stored it into a php variable.

$fromserver=$row['today'];

So $fromserver has value '2014-07-02T05:13:45Z' stored in it.

For showing it to users in readable format, I used strtotime() & date() in php.

Here's my code.

date_default_timezone_set('UTC');
$fs = strtotime($fromserver);
$fromserver_formated = date("Y-m-d H:i:s",$fs);

So, now if I echo() $fromserver_formated, I get the date in a readable format.

echo $fromserver_formated; gives 2014-07-02 05:13:45.

Now I want to create a new variable $toserver using the value of $fromserver & $variable.

$variable is an integer variable containing value 7200.

So to calculate to $toserver, I did this.

$ts=$fs+$variable;
$toserver=date('Y-m-d H:i:s',$ts);

And when I echo $toserver, I get 2014-07-02 07:13:45.

And I want to store $toserver into my database. But not in '2014-07-02 07:13:45' this format but in '2014-07-02T07:13:45z' format like $fromserver.

What to do next? Any suggestions?

2 Answers 2

1

It's manually added date i think there is not any format to convert .try

$fromserver = '2014-07-02 05:13:45';
date_default_timezone_set('UTC');
$fs = strtotime($fromserver);
echo $fromserver_formated = date("Y-m-d\TH:i:s\z",$fs); //2014-07-02T05:13:45z
Sign up to request clarification or add additional context in comments.

Comments

0

I am confused with answers above, where he talk about format for datetime variables already giving not current datetime format or add/sub hours, so I think the right way convert datetime variable string to datetime object and use format as the following:

$fromserver = '2014-07-02 05:13:45';
$tz = new DateTimeZone('Europe/London');
$mydate = new DateTime($fromserver, $tz);
$formated_date = $mydate->format('Y-m-d H:i:s');

Comments

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.