• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 962
  • Last Modified:

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

0
dm404
Asked:
dm404
  • 4
  • 3
1 Solution
 
hernst42Commented:
That is SQL syntax in PHP you need something like this:

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

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

Thanks in advance,

Daniel
0
 
dm404Author Commented:
Sorry that didn't work.

It comes up with

Thu, 01 Jan 1970 00:00:00 +0000 !!
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
hernst42Commented:
What is the content of $edt?
0
 
afzzCommented:
try this
$edt2 = date('Y-m-d', strtotime(strtotime($edt)." plus 2 days"));

Open in new window

0
 
dm404Author Commented:
$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
 
hernst42Commented:
Ok in thiscase this works:

$edt = '2008-10-03';
$edt2 = date('Y-m-d', strtotime($edt)+2*86400);
echo $edt2; // 2008-10-05
0
 
dm404Author Commented:
Yep that works.

Thankyou very much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now