Solved

php mysql add days to date variable

Posted on 2008-06-10
4
1,467 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Have issues with Query MySQL 9 54
Form Processing in PHP 11 29
mysql update statement effect only some rows 4 26
How to keep line breaks when outputting data from database 4 13
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

943 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

17 Experts available now in Live!

Get 1:1 Help Now