Jump to content

How do I do that?


defeated

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.