I am building a project management website which enables users from around the world to login and automatically register their time against various work projects. I need to save their login time to the database using their "local machine" time (the time as it exists for them, not the time of the website host server), and also their timezone information - so that I can determine where and what time in the world each user is logging in from.

I am already familiar with writing PHP code to save records to the database, but what I need to know is... is there a timezone/datetime function or process in PHP to determine the user's local time and timezone?

Recommended Answers

All 4 Replies

What you would need here is some knowledge in ajax and javascript . When a user logs in for example build the time on his local machine using javascript and pass it to the server using Ajax.
You can then save it to the database with the receiving script. For timezones I am not aware but I remember stumbling on something like a timezone method in the javascript Date object.
Hope it helps!

Hello nigelburrell,

A simple solution to your problem can be to first save the timezone(can be called as offset) as a signed number (e.g., +5 or -5 etc) of each user in the database. And when he signed it at a particular time, do calculate his local time by adding this Offset to the UTC.I hope this will be helpful....

What you would need here is some knowledge in ajax and javascript . When a user logs in for example build the time on his local machine using javascript and pass it to the server using Ajax.
You can then save it to the database with the receiving script. For timezones I am not aware but I remember stumbling on something like a timezone method in the javascript Date object.
Hope it helps!

Ok thanks, will look into this timezone method via the javascript Date object a bit more.

Hello nigelburrell,

A simple solution to your problem can be to first save the timezone(can be called as offset) as a signed number (e.g., +5 or -5 etc) of each user in the database. And when he signed it at a particular time, do calculate his local time by adding this Offset to the UTC.I hope this will be helpful....

Yes, I've seen the offset function, might do what you suggested as I think it's the best way. Thanks for your suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.