Jump to content

$tzone difference


RON_ron

Recommended Posts

I've got the user signup time stored in a database formatted to my timezone.

 

Can someone help me to find the difference between the current time and the stored time. This is my code - no success though.

 

$tzone =  new DateTimeZone('Asia/Manila');

$date = new DateTime('now', $tzone);

$currenttime =  $date->format('Y-m-d g:ia');

 

$userTimeFromDB = "2012-09-10 6:20pm";

 

$difference= ($userTimeFromDB - $currenttime);

echo ($difference);

Link to comment
Share on other sites

I'm not really following you. If you stored the time in your timezone and want to know the difference then just calculate the difference between the time in the DB and your current time. How did you store the time based upon your timezone to begin with? You should be able to get what you want using DATEDIFF() to get the number of days difference. Or if, you want the difference in time use TIMEDIFF()

SELECT DATEDIFF(NOW(), date_field) as difference
FROM table

 

But, if you want to work with times across timezones you should be storing it based upon GMT time - not your local time. Then translate the value to the appropriate offset when displaying it.

Link to comment
Share on other sites

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.