Solved

ADDDATE function using a variable

Posted on 2008-06-21
8
954 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

734 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