Link to home
Start Free TrialLog in
Avatar of dtleahy
dtleahyFlag for United States of America

asked on

Server time, not local user's time (php, mySQL)

A quick question:

Timezones around the world... users in different timezones.

I need to compare when a record was updated, not based on local time, but on server time.

I have a datetime field in mySql, default is: 0000-00-00 00:00:00       

I have a form, and that form processing should update a field in a record. If someone in London and someone in Chicago update their record nearly simultaneously, the database should show the times as whatever was correct at the server at the time, not local time. Even though Peter and Paul are 6 hours apart in time zones, if they update nearly simultaneously, I would want:

 2012-03-24 23:49:03       Peter, London
 2012-03-24 23:49:00       Paul, Chicago

Will the php function Now() update the record with server time, or local time? If local, then what function do I need to use, instead.

Thanks!

Dennis
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dtleahy

ASKER

Thanks Dave, for the quick reply,

So...
(from the php file)
$sql="UPDATE mytable SET zdatetime=Now() WHERE (zuserid = $row[vuserid ])";	

Open in new window


Simple as this?

Do I need to format it at all? I don't need to display the data in the zdatetime field, I just need to make a comparison, so I can (for example) query to get the last 10 people who have activated.

Dennis
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dtleahy

ASKER

Thanks, Ray!

Excellent info at that link! Thank you so much for taking the time (a few years ago) to amass that accumulated knowledge into what is a whitepaper. Great resource!

In my current programming situation, the only thing this datetime field will be used for is to do an ORDER BY in the SQL statement. I'll never display the field data and the people around the world will never need to know the offset from GMT, or do any datetime math for example.

This has nothing to do with auctions, but as a good example, imagine an item being auctioned off and people around the world are bidding. I would need to know what time they hit the server, not what time it was at their particular locality.

The exact reason I want this is so that I can display a list of the most recent 10 people that have signed-up to a website I'm building, (no matter where they are in the world.)

Dennis
Avatar of dtleahy

ASKER

Thanks, Dave and Ray! You guys are gems!<br />-Dennis