jimcarry05 Posted January 1, 2010 Share Posted January 1, 2010 Hello guys, I am working on a project. And I want to insert the expiry date of the products. So how can I insert the expiry date into mysql using PHP script. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/186859-how-to-insert-date-into-mysql/ Share on other sites More sharing options...
premiso Posted January 1, 2010 Share Posted January 1, 2010 If I am not mistaken, you can do something like: INSERT INTO table (date_field, other_field) VALUES (DATE_ADD(NOW(), INTERVAL 1 DAY), 'other field stuff'); References: MySQL Date and Time Functions Quote Link to comment https://forums.phpfreaks.com/topic/186859-how-to-insert-date-into-mysql/#findComment-986810 Share on other sites More sharing options...
jimcarry05 Posted January 5, 2010 Author Share Posted January 5, 2010 Thanks :-) Quote Link to comment https://forums.phpfreaks.com/topic/186859-how-to-insert-date-into-mysql/#findComment-988761 Share on other sites More sharing options...
jimcarry05 Posted January 5, 2010 Author Share Posted January 5, 2010 Hello, When I run this code. It stored 0000-00-00 on my database. Here is PHP CODE $date = $_GET["date"]; $query = "INSERT INTO tablename (col_name, col_date) VALUES ('Manual Date', '$date')"; And here is HTML Date: <input name="date" type="text"> Please correct this code. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/186859-how-to-insert-date-into-mysql/#findComment-988775 Share on other sites More sharing options...
rajivgonsalves Posted January 5, 2010 Share Posted January 5, 2010 you will have to make sure that the date is in YYYY-MM-DD format e.g 2010-01-05 for it to insert properly otherwise it will be invalid and a 0000-00-00 date will be inserted Quote Link to comment https://forums.phpfreaks.com/topic/186859-how-to-insert-date-into-mysql/#findComment-988793 Share on other sites More sharing options...
jimcarry05 Posted January 5, 2010 Author Share Posted January 5, 2010 I am inserting date in this format YYYY-MM-DD. eg. 2010-01-01 Quote Link to comment https://forums.phpfreaks.com/topic/186859-how-to-insert-date-into-mysql/#findComment-988846 Share on other sites More sharing options...
rajivgonsalves Posted January 5, 2010 Share Posted January 5, 2010 you'll have to check your query try echo $query; and see if its showing up correctly, also what is the column type for col_date Quote Link to comment https://forums.phpfreaks.com/topic/186859-how-to-insert-date-into-mysql/#findComment-988867 Share on other sites More sharing options...
jimcarry05 Posted January 5, 2010 Author Share Posted January 5, 2010 Solved. Any mod here ? Please close this thread......................... Quote Link to comment https://forums.phpfreaks.com/topic/186859-how-to-insert-date-into-mysql/#findComment-988938 Share on other sites More sharing options...
premiso Posted January 5, 2010 Share Posted January 5, 2010 You can close it by clicking the "Mark Solved" button on top left hand corner of the "Quick Reply". Quote Link to comment https://forums.phpfreaks.com/topic/186859-how-to-insert-date-into-mysql/#findComment-988948 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.