Forum Moderators: coopster

Message Too Old, No Replies

Server Date/Time to Local Time

Insert/display based on local time, NOT server time

         

mvaz

1:31 pm on Mar 19, 2010 (gmt 0)

10+ Year Member



Hi all

I have a form that has an option for the user to select date, month and year, which is later concatenated and inserted into mysql database as dd-yy-mmmm; and the data that is posted with this needs to be displayed on this date.

The problem is, the server on which my site is hosted is based in Arizona, whilst I am here in the UK and most of our visitors are from the UK and Asian region.

The data that was posted through the form does not get displayed until it is 7am here, for it is just after midnight in Arizona. I want the data to be displayed soon after GMT midnight here rather than midnight in Arizona.

Is there a way this can be achieved and if so, could the learned and more experienced guys here guide me in the right direction please?

Many thanks in advance - Melwyn

Anyango

2:19 pm on Mar 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First of all, a server has no way of knowing the time set on client's computer, until you send it in request.

There are two very easy methods which can work for you

1) If you know the server time, and you can store the difference between server timezone and UK timezone, in your db. for example if server time is 7 hours ahead of your time, you can store server time - 7 hours to your db.

2) Simply include the current timestamp in a hidden field in your form (maybe via javascript) and send it to server along with the data save request, and save that.

Just 2 of many ways possible

Readie

2:50 pm on Mar 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you could just set the timezone?

[php.net...]

Readie

6:22 pm on Mar 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



date_default_timezone_set('Europe/London');

rocknbil

7:00 pm on Mar 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



from the UK and Asian region.


Unreliably: get the user's local time using Javascript.

Slightly more reliably: use IP address and any other headers sent by the browser to get a geo location of the user's location and map the time offset accordingly.

Have a look at what vBulletin (and others) do, it seems relatively accurate.

dreamcatcher

8:38 pm on Mar 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



date_default_timezone_set won`t work if you are running PHP4.

dc