jobs1109 Posted August 26, 2011 Share Posted August 26, 2011 Hi Everyone, I am trying to create a variable with the current date and then insert it into a mysql database. Here is what I have so far. $DatePostedOn= date("F j, Y, g:i a"); when I insert the variable into the table it shows " 0000-00-00 00:00:00 " What am I doing wrong ? Please help Quote Link to comment https://forums.phpfreaks.com/topic/245742-variable-with-current-date/ Share on other sites More sharing options...
Psycho Posted August 26, 2011 Share Posted August 26, 2011 What kind of MySQL field are you using to store the value? I fusing one of the date type fields then the format has to be very specific. http://dev.mysql.com/doc/refman/5.1/en/datetime.html [Moving to MySQL forum] Quote Link to comment https://forums.phpfreaks.com/topic/245742-variable-with-current-date/#findComment-1262172 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 the format in mysql is not the same as you're using. convert it to date("Y-m-d H:i:s"); before inserting. Quote Link to comment https://forums.phpfreaks.com/topic/245742-variable-with-current-date/#findComment-1262173 Share on other sites More sharing options...
jobs1109 Posted August 26, 2011 Author Share Posted August 26, 2011 Thanks that works. Now when I get the results from the mysql query and print it out it show as " 2011-08-26 04:07:23 " How do I get it to show as 08/26/2011 ? Quote Link to comment https://forums.phpfreaks.com/topic/245742-variable-with-current-date/#findComment-1262182 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 Now when I get the results from the mysql query and print it out it show as " 2011-08-26 04:07:23 " How do I get it to show as 08/26/2011 ? echo date("m/d/Y",strtotime('2011-08-26 04:07:23')); Quote Link to comment https://forums.phpfreaks.com/topic/245742-variable-with-current-date/#findComment-1262183 Share on other sites More sharing options...
jobs1109 Posted August 26, 2011 Author Share Posted August 26, 2011 Hi here is how it's being retreived from database " <?php echo $rsjobs['PostedOnDate'];?> $rsjobs is the id corresponding to that row of data. How do I format this to "08/26/2011 " ? " Quote Link to comment https://forums.phpfreaks.com/topic/245742-variable-with-current-date/#findComment-1262190 Share on other sites More sharing options...
jobs1109 Posted August 26, 2011 Author Share Posted August 26, 2011 <?php echo $rsjobs['PostedOnDate'];?> time show usp as 2011-08-26 04:12:57 I would like to get it to show up as 08/26/2011 Quote Link to comment https://forums.phpfreaks.com/topic/245742-variable-with-current-date/#findComment-1262194 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 Did you try my code? (changing the date to your var?) echo date("m/d/Y",strtotime($rsjobs['PostedOnDate'])); Quote Link to comment https://forums.phpfreaks.com/topic/245742-variable-with-current-date/#findComment-1262198 Share on other sites More sharing options...
jobs1109 Posted August 26, 2011 Author Share Posted August 26, 2011 Hi Thanks this code work. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/245742-variable-with-current-date/#findComment-1262202 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.