defeated Posted March 19, 2008 Share Posted March 19, 2008 Hi, How do I insert a date eg now() and add on a number of days x to make an expiry date column for a my mysql database? The number of days (x) is selected as part of a large unwieldy form when data is first submitted to the db and can be user selected to be anywhere between 1 and 60. I called the day number (x) $expiredays. ie. $expiredays=$_REQUEST['expiredays']; Quote Link to comment Share on other sites More sharing options...
fenway Posted March 19, 2008 Share Posted March 19, 2008 All I am trying to do is find the correct syntax for the following.... mysql_query("INSERT INTO database (post_date, expire_date, etc.) VALUES(CURDATE(),ADDDATE(NOW(),INTERVAL <?php echo $number of days to expiry ; ?> DAY),etc.)")or die(mysql_error()); That seems fine to me... I prefer NOW() + INTERVAL <?php echo $number of days to expiry ; ?> DAY, saves a function. Quote Link to comment Share on other sites More sharing options...
defeated Posted March 19, 2008 Author Share Posted March 19, 2008 Worked out where I was going wrong. dont need the <?php echo $daystoexpiry ; ?> because it is already in a php line. so now it's mysql_query("INSERT INTO database (post_date, expiry_date, etc.) VALUES(CURDATE(),ADDATE(NOW(),$daystoexpiry),etc)") or die(mysql_error()); A little shorter and seems to work. Quote Link to comment Share on other sites More sharing options...
fenway Posted March 19, 2008 Share Posted March 19, 2008 Oops... missed the whole php thing. Quote Link to comment 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.