Jump to content

add days to date


metrostars

Recommended Posts

Hi,

Is it possible to (using sql now feature preferably), to insert todays date plus a number of days thaht i set.

Everything i have tried has not added a month once 31 days is reached.

I have no idea how to do this. I have tried the manuals on php.net but i cannot get it to work.

tHanks
Link to comment
Share on other sites

[code]
$nowdate = strtotime("now");  // creates a date string of todays date
$newdate = strtotime("+2 day", $nowdate); // adds 2 days onto that date string
$mydate = date("d-m-Y", $newdate) //creates a new date object from that string (03-08-2006)
[/code]

is one way to do it
Link to comment
Share on other sites

try this:
[code]
<?php
$days = 3;
mysql_query("INSERT INTO tableName (dateColumn) VALUES (DATE_ADD(CURDATE(), INTERVAL $days DAY))");
?>
[/code]
notice i'm using CURDATE(), but it also returns (obviously) the current date like NOW() would.
Link to comment
Share on other sites

[quote author=paul2463 link=topic=102562.msg407193#msg407193 date=1154434755]
[code]<?php
$nowdate = strtotime("now");  // creates a date string of todays date
$newdate = strtotime("+2 day", $nowdate); // adds 2 days onto that date string
$mydate = date("d-m-Y", $newdate) //creates a new date object from that string (03-08-2006)
?>[/code]

is one way to do it
[/quote]
This can be done much more simply:
[code]<?php
$mydate = date('Y-m-d',strtotime('today +2 days'));
?>[/code]

Ken
Link to comment
Share on other sites

[quote author=metrostars link=topic=102562.msg407176#msg407176 date=1154432061]
Hi,

Is it possible to (using sql now feature [u][b]preferably[/b][/u]), to insert todays date plus a number of days thaht i set.

Everything i have tried has not added a month once 31 days is reached.

I have no idea how to do this. I have tried the manuals on php.net but i cannot get it to work.

tHanks
[/quote]

Definition of preferably: More desirable or worthy than another; preferred:

Meaning: He would prefer it be sql, but that does not rule out the chance of it being done another way.
Link to comment
Share on other sites

[quote author=hostfreak link=topic=102562.msg407296#msg407296 date=1154446035]
Definition of preferably: More desirable or worthy than another; preferred:

Meaning: He would prefer it be sql, but that does not rule out the chance of it being done another way.

[/quote]
wow... and the sarcasm runs rampant. i'm aware of what "preferably" means. it would make sense, however, for people to spend the time helping the poster come up with a solution in his "prefered" method.

ken, i apologize, your post does indeed (quite obviously, actually) answer the other response. thanks for the clarification.
Link to comment
Share on other sites

[quote]Code:
<?php
$nowdate = strtotime("now");  // creates a date string of todays date
$newdate = strtotime("+2 day", $nowdate); // adds 2 days onto that date string
$mydate = date("d-m-Y", $newdate) //creates a new date object from that string (03-08-2006)
?>
is one way to do it

This can be done much more simply:

Code:
<?php
$mydate = date('Y-m-d',strtotime('today +2 days'));
?>
Ken [/quote]

thanks for that Ken but I spilt it into three tasks to identify what each step actually did, once each step is understood then the shortened version could be used.
Paul


Link to comment
Share on other sites

Thanks to everyone who answered. All worked perfectly.

The SQL one wouldn't work when i inserted the syntax directly into the database (it just showed 0000-00-00) all the time, o i had to select it from the database on the previous page and pass the value via. URL parameter.

Thanks alot.
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.