Correcting server time inaccuracy
Moderator: General Moderators
Correcting server time inaccuracy
Hi guys. As my first post here I'd like to ask how on earth do you correct an inaccuracy of your servers time?
I am based in the UK and my host is in the US. My SQL server's time seems to be OK (excusing the 6 hour time difference) but if I echo date() I get a time that is 6 hours and 11 minutes off GMT.
All I need to do is make the date and time match the date and time here. My primary concern is that if I just add a few hours and minutes thet days will be incorrect during that 6 hour 11 minute period as the day/month etc roll over.
I then need to insert this date and time to a MySQL field.
Does that make any sense? I hope someone can help me, this has been driving me up the wall for ages!
I am based in the UK and my host is in the US. My SQL server's time seems to be OK (excusing the 6 hour time difference) but if I echo date() I get a time that is 6 hours and 11 minutes off GMT.
All I need to do is make the date and time match the date and time here. My primary concern is that if I just add a few hours and minutes thet days will be incorrect during that 6 hour 11 minute period as the day/month etc roll over.
I then need to insert this date and time to a MySQL field.
Does that make any sense? I hope someone can help me, this has been driving me up the wall for ages!
[php_man]date[/php_man]
[php_man]gmdate[/php_man]Returns a string formatted according to the given format string using the given integer timestamp or the current local time
Btw, if your MySQL column is of type TIMESTAMP you will need MySQL's FROM_UNIXTIME functionIdentical to the date() function except that the time returned is Greenwich Mean Time (GMT). For example, when run in Finland (GMT +0200), the first line below prints "Jan 01 1998 00:00:00", while the second prints "Dec 31 1997 22:00:00".
Thanks but all you've done is referred me straight to the first places I looked but I cannot get PHP.NET's solutions to work properly.
As for the MySQL entries, they are DATETIME and they work perfectly and are nothing to worry about, I jyust mentioned them as a side note, I'd just ignore them if I were you!
As for the MySQL entries, they are DATETIME and they work perfectly and are nothing to worry about, I jyust mentioned them as a side note, I'd just ignore them if I were you!
True, but if they're 11 minutes off the hour, then their server time is incorrect. There is no timezone that is only 11 minutes
. If they corrected their time even locally, then you could correct the hour, and not need to worry about minutes.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Correcting server time inaccuracy
It will be incorrect for the server, but will be correct for your timezone. Adding 6 hours to whatever date() gives you will certainly give the wrong date and time for the server. If your interested in making it correct for your timezone though, adding 6 hours should work.Antnee wrote:My primary concern is that if I just add a few hours and minutes thet days will be incorrect during that 6 hour 11 minute period as the day/month etc roll over.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
For Indian Standard Time I add the difference.
Code: Select all
$today=mysql_fetch_assoc(mysql_query("SELECT DATE_FORMAT(NOW()+INTERVAL '09:30' HOUR_MINUTE,'%W, %D %M') AS IST"));OK, I did this:
and I got this back:
If I type the command directly into MySQL I get this:
Any ideas? I'm starting to think this just isn't going to work for me!
Code: Select all
$today=mysql_fetch_assoc(mysql_query("SELECT DATE_FORMAT(NOW()+INTERVAL '06:00' HOUR_MINUTE,'%W, %D %M') AS GMT"));
echo $today;Code: Select all
ArrayCode: Select all
Saturday, 28th AugustJust figured that! Thanks! (Newbies eh?)feyd wrote:echo $today['GMT'];
Got the required result with
Code: Select all
$today=mysql_fetch_assoc(mysql_query("SELECT DATE_FORMAT(NOW()+INTERVAL '05:00' HOUR_MINUTE,' %W %D %M %Y at %H:%i:%s') as GMT"));
echo $today['GMT'];