Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php mysql add days to date variable

Posted on 2008-06-10
4
Medium Priority
?
1,523 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
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.
Suggested Courses

927 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