bugzy Posted April 21, 2012 Share Posted April 21, 2012 Ok I got this column "date_reg" on my table which has a "datetime" type. It's giving me a value like "2012-04-20 04:28:03" The problem is, when I'm trying to insert on that column using this format <?php $datenow = date('m/d/Y h:i:s a', time()); ?> it's giving me a value of "0000-00-00 00:00:00" which is suppose to be the current date and time the user add on that table. Anyone knows how I can fix this? Quote Link to comment https://forums.phpfreaks.com/topic/261390-simple-timedate-problem/ Share on other sites More sharing options...
MMDE Posted April 21, 2012 Share Posted April 21, 2012 04/22/2012 12:35:43 am Is what it said when I ran the code on my server using your code. I think this is what it really wants: <?php $datenow = date('Y-m-d H:i:s', time()); ?> Which on my server resulted in: 2012-04-22 00:38:35 Quote Link to comment https://forums.phpfreaks.com/topic/261390-simple-timedate-problem/#findComment-1339417 Share on other sites More sharing options...
Eiolon Posted April 21, 2012 Share Posted April 21, 2012 The DATETIME column is limited to YYYY-MM-DD HH:MM:SS format. Anything else is illegal. Simply insert it that way, then format it as you desire when showing it to the user. You can also store it as a unix timestamp and format it as well. Many people find a unix timestamp to be easier to work with when doing advanced mathematics. Quote Link to comment https://forums.phpfreaks.com/topic/261390-simple-timedate-problem/#findComment-1339418 Share on other sites More sharing options...
bugzy Posted April 21, 2012 Author Share Posted April 21, 2012 04/22/2012 12:35:43 am Is what it said when I ran the code on my server using your code. I think this is what it really wants: <?php $datenow = date('Y-m-d H:i:s', time()); ?> Which on my server resulted in: 2012-04-22 00:38:35 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/261390-simple-timedate-problem/#findComment-1339419 Share on other sites More sharing options...
MMDE Posted April 21, 2012 Share Posted April 21, 2012 The DATETIME column is limited to YYYY-MM-DD HH:MM:SS format. Anything else is illegal. Simply insert it that way, then format it as you desire when showing it to the user. You can also store it as a unix timestamp and format it as well. Many people find a unix timestamp to be easier to work with when doing advanced mathematics. Yes, unix timestamp is nice, but both is stored the same way and handled almost the same way. Though I think too a unix timestamp is easier to work with, but it's not as easy to look at with the human eye in the database. You can make the DATETIME return unix time by using UNIX_TIMESTAMP(). Quote Link to comment https://forums.phpfreaks.com/topic/261390-simple-timedate-problem/#findComment-1339424 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.