?
Solved

ADDDATE function using a variable

Posted on 2008-06-21
8
Medium Priority
?
958 Views
Last Modified: 2012-05-05
Hi there,

I'm having trouble using ADDDATE function in PHP. I want to add 2 days to m $edt variable that I set at the top of my page.

I'm guessing it should follow these lines...

ADDDATE(date, INTERVAL 2 DAY).

I can't get the variable $edt to work tho. I get a Parse error: syntax error, unexpected T_LNUMBER

Here's a snippet of my code...
$edt2 = ADDDATE("$edt", INTERVAL 2 DAY);
 
echo $edt2;

Open in new window

0
Comment
Question by:dm404
  • 4
  • 3
8 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 21836936
That is SQL syntax in PHP you need something like this:

$edt2 = date('r', strtotime("$edt plus 2 days"));
0
 

Author Comment

by:dm404
ID: 21836959
Hi,

Yep that works although I need the value to be in a YYYY-MM-DD

Thanks in advance,

Daniel
0
 

Author Comment

by:dm404
ID: 21836964
Sorry that didn't work.

It comes up with

Thu, 01 Jan 1970 00:00:00 +0000 !!
0
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.

 
LVL 48

Expert Comment

by:hernst42
ID: 21836971
What is the content of $edt?
0
 
LVL 4

Expert Comment

by:afzz
ID: 21836978
try this
$edt2 = date('Y-m-d', strtotime(strtotime($edt)." plus 2 days"));

Open in new window

0
 

Author Comment

by:dm404
ID: 21837039
$edt is a variable set in two ways.

1) Form is submitted, uses a JS calendar so the value will always be in the format YYYY-MM-DD.
2) Form not submitted takes current date in format YYYY-MM-DD.

afzz your code returns 1970-01-01, which is the correct format just not the correct date.

Thanks again,#
Daniel
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 total points
ID: 21837048
Ok in thiscase this works:

$edt = '2008-10-03';
$edt2 = date('Y-m-d', strtotime($edt)+2*86400);
echo $edt2; // 2008-10-05
0
 

Author Comment

by:dm404
ID: 21837056
Yep that works.

Thankyou very much!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

840 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