Jump to content

Recommended Posts

  • 2 weeks later...

I'm not sure how you mean. From your question and the link I gave I am guessing that you now have something like this

 

   function myTimeDiff ($d1, $d2)
   {
    $dt1 = new DateTime($d1);
    return $dt1->diff(new DateTime($d2))->format('%a Days %h Hours');
   }

$date_1 = '2013-02-01 04:00:00';
$date_2 = '2013-02-03 07:30:00';

echo myTimeDiff($date_1, $date_2);    // --> 2 Days 3 Hours

 

What result are you getting and what result is required?

If you want to specify the timezone of the dates: You'll need to create a DateTimeZone object, of the desired timezone, then send it as the second parameter when creating the DateTime object.

 

If you want to retrieve the timezone, and its offset (compared to GMT), then you have the "e" and "O" flags for the DateTime::format () method.

 

You can also, if I'm not completely mistaken, change the timezone and automatically adjust the date/time of the object. To do this, just set the timezone using the proper method for the DateTime object.

Edited by Christian F.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.