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']; Link to comment https://forums.phpfreaks.com/topic/96877-how-do-i-do-that/ 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. Link to comment https://forums.phpfreaks.com/topic/96877-how-do-i-do-that/#findComment-495879 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. Link to comment https://forums.phpfreaks.com/topic/96877-how-do-i-do-that/#findComment-495938 Share on other sites More sharing options...
fenway Posted March 19, 2008 Share Posted March 19, 2008 Oops... missed the whole php thing. Link to comment https://forums.phpfreaks.com/topic/96877-how-do-i-do-that/#findComment-495960 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.