Solved

ADDDATE function using a variable

Posted on 2008-06-21
8
949 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
Comment Utility
That is SQL syntax in PHP you need something like this:

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

Author Comment

by:dm404
Comment Utility
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
Comment Utility
Sorry that didn't work.

It comes up with

Thu, 01 Jan 1970 00:00:00 +0000 !!
0
 
LVL 48

Expert Comment

by:hernst42
Comment Utility
What is the content of $edt?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Expert Comment

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

Open in new window

0
 

Author Comment

by:dm404
Comment Utility
$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 500 total points
Comment Utility
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
Comment Utility
Yep that works.

Thankyou very much!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

743 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

18 Experts available now in Live!

Get 1:1 Help Now