views:

25

answers:

2

hi,

I would like to know how to handle date and time if we do any site where we ask users to create evetns like evite.com. my confusion is, if I create an event for Aug 5th and then invite 200 persons from different places(outside the event country), how evite sends the reminder because the time is different in some countries i.e. it will be still 4th in some country but 5th in some countries. Also, when we do any time calcualtion it takes the servers time where the site is hosted, is this the right way and just leave it like that?

please throw some light.

regards

A: 

Convert all the time to GMT before storing. That way you have a common date/time for the entire earth.

You also need to have your members specify the time zone they are in, so that you can display the events in the correct time for them.

iWantSimpleLife
This is not sufficient. See the article I've linked to.
Artefacto
+2  A: 

The server time is useless.

For future events, you have to store both the time of the event in the form "yyyy-mm-dd hh:mm:ss" and the timezone of the event (e.g. "Europe/Lisbon"). Do not store the timestamp and the timezone unless it's some kind of astronomical event whose time depends not on the legal time of the country/region where the event happens but on some absolute time point.

Then, you can calculate the time of the event like this (e.g.):

//Let's say the event happens in Lisbon
$d = new DateTime("2010-08-10 17:00:00", new DateTimeZone("Europe/Lisbon"));
echo "The event occurs on ", $d->format("r"), " (local time).";
//let's say the user is in India
$d2 = $d->setTimezone(new DateTimeZone("Asia/Calcutta"));
echo "The event occurs on ", $d->format("r"), " (your time).";

Further reading: Storing Date/Times in Databases

Artefacto
hi, thanks. i will read this article and try out something tomorrow. thanks, I am hoping I can use these techniques with my current setup. I am getting the date from the user in 2010-08-02 format, i need to see how I can manipulate based on your notes and the article to display the correct event date through out the world. I use this date and then used some javscript to calculate the difference in days-hrs-month on the webpage like "event will happen in 3D4h10M. I will have to see if i need to modify several things. but again I appreciate your quick help.
Jay