Solved

php mysql add days to date variable

Posted on 2008-06-10
4
1,462 Views
Last Modified: 2008-06-10
trying to add a number of days variable to a date variable... here is what I have so far (not working):

$newDate = strtotme("+$days_to_add day", $existing_date());
echo "<br>Days added: $days_to_add";
echo "<br>New date: $newDate<br>";
0
Comment
Question by:newbe101
  • 2
  • 2
4 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 21752698
What is the content of $existing_date?

should lokk like this:
$newDate = strtotime("+$days_to_add day", $existing_date);
echo "<br>Days added: $days_to_add";
echo "<br>New date: $newDate<br>";
0
 

Author Comment

by:newbe101
ID: 21752743
$existing_date is a date pulled from my mysql database (0000-00-00).
here is my echo results:
Days added: 60 to 2008-06-08
New date: 5186008
I don't know why new date looks like that... shouldn't it be in the 0000-00-00 format?
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 21752799
strtotime returns an unix timestamp which must be formated with date to your desired output

justreplace the hard coded things with your variables
echo date("Y-m-d", strtotime("2008-06-08 +5 days")) ."\n";

$newDate = date("Y-m-d", strtotime("$existing_date +$days_to_add day days"))
0
 

Author Comment

by:newbe101
ID: 21755520
perfect... thanks again!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now