Solved

ADDDATE function using a variable

Posted on 2008-06-21
8
950 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
 
LVL 48

Expert Comment

by:hernst42
ID: 21836971
What is the content of $edt?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Animated .jpg? 13 59
Php pie charts 3 26
How to loop through records  using SELET COUNT 2 14
Scope of $_SESSION 17 27
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…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

21 Experts available now in Live!

Get 1:1 Help Now