Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php mysql add days to date variable

Posted on 2008-06-10
4
Medium Priority
?
1,512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this article, we’ll look at how to deploy ProxySQL.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

688 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