nclocl Posted August 21, 2011 Share Posted August 21, 2011 I'm looking to enter the current time and date into a mysql database using php. My current code looks like this: $now = date("m/d/y",time()); I then insert $now into the table into a datetime column. This all works but the time when read from the column appears as 0000-00-00 00:00:00. Any ideas what I'm doing wrong? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/245348-current-time-and-date/ Share on other sites More sharing options...
JasonLewis Posted August 21, 2011 Share Posted August 21, 2011 You can simply use the NOW() function in MySQL for this kind of thing. INSERT INTO users (name, date) VALUES ('Jaysonic', NOW()) Quote Link to comment https://forums.phpfreaks.com/topic/245348-current-time-and-date/#findComment-1260111 Share on other sites More sharing options...
nclocl Posted August 21, 2011 Author Share Posted August 21, 2011 perfect, thank you Is there any way to tell it what timezone I'm in or is that related to the mysql server? Quote Link to comment https://forums.phpfreaks.com/topic/245348-current-time-and-date/#findComment-1260115 Share on other sites More sharing options...
JasonLewis Posted August 21, 2011 Share Posted August 21, 2011 It's determined by the server, but you can specify a timezone for MySQL to run in to make things run a little smoother. Or you can handle timezones directly in PHP. Check out the documentation on timezones for MySQL. I personally hate dealing with timezones, it makes things so complicated some times. Well, it makes them seem more complicated then they should. Quote Link to comment https://forums.phpfreaks.com/topic/245348-current-time-and-date/#findComment-1260116 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.