Jump to content

Converting time to users localtime


Clarkeez

Recommended Posts

Hey..

 

I need some sort of function to convert the 'datetime' stamp from my mysql table row.

It needs to convert that time into the users local time.

 

I've searched around but nothing seems related to what I need.

 

Anyone know good way to do this?

Link to comment
Share on other sites

Do you know the timezone for the user? If so, converting a time to another timezone is a simple task. Ideally, I would store the time from GMT, but even if you have it stored in a different timezone you can still convert from that to another. But, the real question is whether you have captured the timezone for the user, such as having them select their timezone when they create an account. If you have not provided a means for the user to select their timezone, there are ways to auto-detect it via JavaScript, but I'm not sure how foolproof that is.

Link to comment
Share on other sites

Thanks guys, I suppose I should get their timezone with the registration form.

 

Erm, so once I have that, how would i actually do it..

 

something like, for example..

 

mysql_connect blah blah

$q = mysql_query("SELECT p.time_posted AS time_posted, u.timezone AS timezone FROM post.p LEFT OUTER JOIN user u ON u.id = p.poster WHERE p.id = 'whatever'"); // time_posted field type is datetime

$d = mysql_fetch_array($q);

 

$localtime = idontknowthisbit_somefunction?($d['time_posted'], $d['timezone']);

echo $localtime;

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.