Link to home
Start Free TrialLog in
Avatar of dm404
dm404

asked on

ADDDATE function using a variable

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

Avatar of hernst42
hernst42
Flag of Germany image

That is SQL syntax in PHP you need something like this:

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

ASKER

Hi,

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

Thanks in advance,

Daniel
Avatar of dm404

ASKER

Sorry that didn't work.

It comes up with

Thu, 01 Jan 1970 00:00:00 +0000 !!
What is the content of $edt?
try this
$edt2 = date('Y-m-d', strtotime(strtotime($edt)." plus 2 days"));

Open in new window

Avatar of dm404

ASKER

$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
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dm404

ASKER

Yep that works.

Thankyou very much!