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
https://forums.phpfreaks.com/topic/16197-add-days-to-date/
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
https://forums.phpfreaks.com/topic/16197-add-days-to-date/#findComment-66994
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
https://forums.phpfreaks.com/topic/16197-add-days-to-date/#findComment-67023
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
https://forums.phpfreaks.com/topic/16197-add-days-to-date/#findComment-67087
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
https://forums.phpfreaks.com/topic/16197-add-days-to-date/#findComment-67154
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
https://forums.phpfreaks.com/topic/16197-add-days-to-date/#findComment-67641
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
https://forums.phpfreaks.com/topic/16197-add-days-to-date/#findComment-67789
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.