Jump to content

Recommended Posts

Hi,

 

I have developed a php/mysql application which I want my members to be able to see say forum posts in their local time zone. Their time zone info would be stored in the members table of the database, so a member living in Paris would have a +1 hr time zone difference stored in their profile from my server in London.

 

I have worked out from loads of searching that the following piece of script can adjust the current time (NOW) by adding or subtracting what is stored in that database field:

 

function getLocalTime($tm, $offset){ 
  return ($tm - date("Z", $tm)) + (3600 * $offset); 
} 


// get current local time in bangkok 
echo date("H:i:s d-m-y", getLocalTime(mktime(), $row_rs_timezone['difference'])). "<br>"; 

 

And I know that this line of code shows the date of the entry from the database data:

 

<?php echo date ("d M Y",strtotime($row_wall ['wall_date'])); ?>

 

How can I know marry the two up? I want to retrieve the date and time from the database item, say the forum post, and then use the first script I showed to calculate the difference?

 

Many thanks in advance :)

Link to comment
https://forums.phpfreaks.com/topic/153906-time-zone-support/
Share on other sites

Can you perhaps approach it differently using this function: CONVERT_TZ?

That looks great for the database, I am guessing that would change all dates in the database? How can I use in my php page. One of my members may be located in Paris, while another member may be located in New York, while another member in Sydney. They all need to see the timestamp stored in the database +or- their time difference from GMT.
Link to comment
https://forums.phpfreaks.com/topic/153906-time-zone-support/#findComment-809279
Share on other sites

I've looked into this more:

 

I've read that for dealing with timezone sensitive things, a common method is to store the time values in Epoch time (Unix time,seconds since jan 1, 1970).

 

Here are some threads:

http://forums.devnetwork.net/viewtopic.php?f=19&t=92892

http://billauer.co.il/blog/2009/03/mysql-datetime-epoch-unix-time/

 

Or you can store the times in GMT/UTC time (+0) and use the convert_tz function (WHICH IS A MYSQL FUNCTION) when pulling them.

SELECT postdate AS 'EST', CONVERT_TZ(postdate,'+00:00','-3:00') as 'PST' FROM testtest

Which would pull the same column twice, showing the original date (my server is located in EST time, and my equivalent date in PST local time)

Link to comment
https://forums.phpfreaks.com/topic/153906-time-zone-support/#findComment-810296
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.