sandrine Posted May 17, 2009 Share Posted May 17, 2009 when i insert some info into my mysql using a form on my website the date and time that are auto inserted into my database are wrong. the date is minus one day and the time is also many hours behind. iam using a form to get the info and a simlpe php script does the inserting into my database. can any one point me in the right direction thanks. Quote Link to comment https://forums.phpfreaks.com/topic/158461-date-and-time-that-are-auto-inserted-into-my-database-are-wrong/ Share on other sites More sharing options...
Ken2k7 Posted May 17, 2009 Share Posted May 17, 2009 It shouldn't be that far behind. I assume the DB's time settings are in a different time zone. Quote Link to comment https://forums.phpfreaks.com/topic/158461-date-and-time-that-are-auto-inserted-into-my-database-are-wrong/#findComment-835698 Share on other sites More sharing options...
Daniel0 Posted May 17, 2009 Share Posted May 17, 2009 Check that your server's clock is running correctly. You might want to use NTP to keep the server's time synchronized. Quote Link to comment https://forums.phpfreaks.com/topic/158461-date-and-time-that-are-auto-inserted-into-my-database-are-wrong/#findComment-835712 Share on other sites More sharing options...
shamuraq Posted May 17, 2009 Share Posted May 17, 2009 whats NTP? How does it work? Quote Link to comment https://forums.phpfreaks.com/topic/158461-date-and-time-that-are-auto-inserted-into-my-database-are-wrong/#findComment-835833 Share on other sites More sharing options...
Daniel0 Posted May 17, 2009 Share Posted May 17, 2009 NTP is short for Network Time Protocol. It's a protocol for synchronizing clocks. You can only set that up if you are the administrator of the server. I don't know if your server's clock is off though. You can check that yourself by echoing the date and time to see if it's correct or not. Quote Link to comment https://forums.phpfreaks.com/topic/158461-date-and-time-that-are-auto-inserted-into-my-database-are-wrong/#findComment-835840 Share on other sites More sharing options...
sandrine Posted May 19, 2009 Author Share Posted May 19, 2009 ok i figured it out you can change the time zone quite eqsily but i cant as iam on a free hosting so cant access .htaccess fully or php.ini at all. the server is in the usa and iam in the uk so i need to either upgrade and get paid hosting or find a free host based in the uk thanks for the help tho. Quote Link to comment https://forums.phpfreaks.com/topic/158461-date-and-time-that-are-auto-inserted-into-my-database-are-wrong/#findComment-837160 Share on other sites More sharing options...
xtopolis Posted May 21, 2009 Share Posted May 21, 2009 You can't create your own php.ini on a per folder basis even? Perhaps this might work: http://us.php.net/manual/en/function.date-default-timezone-set.php Quote Link to comment https://forums.phpfreaks.com/topic/158461-date-and-time-that-are-auto-inserted-into-my-database-are-wrong/#findComment-838636 Share on other sites More sharing options...
roopurt18 Posted May 29, 2009 Share Posted May 29, 2009 Postgre's timestamp fields support with timezone or without timezone. If the database you are using does the same, then you can just insert it with the correct timezone and display it with the user's timezone. Then it will all be correct! Quote Link to comment https://forums.phpfreaks.com/topic/158461-date-and-time-that-are-auto-inserted-into-my-database-are-wrong/#findComment-844643 Share on other sites More sharing options...
Lyleyboy Posted August 11, 2009 Share Posted August 11, 2009 Really simple way would be to add the hours on. So any time zone is a whole number of hours plus or minus of gmt. Just work out the difference and before you post the date to the table add or subtract the difference. Very quick and dirty. :-) Quote Link to comment https://forums.phpfreaks.com/topic/158461-date-and-time-that-are-auto-inserted-into-my-database-are-wrong/#findComment-895942 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.