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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.