current date+4 days

Posted on 2011-03-10
Last Modified: 2012-06-27
current date+4 days
Question by:rgb192
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
  • 3
  • 2
LVL 15

Expert Comment

ID: 35097635
This function allows the addition of day(s),month(s),year(s) to the original date while still preserving the Hours, minutes and seconds
You can also modify to add to hours, miuntes and even seconds.
function add_date($givendate,$day=0,$mth=0,$yr=0) {
      $cd = strtotime($givendate);
      $newdate = date('Y-m-d h:i:s', mktime(date('h',$cd),
    date('i',$cd), date('s',$cd), date('m',$cd)+$mth,
    date('d',$cd)+$day, date('Y',$cd)+$yr));
      return $newdate;


Author Comment

ID: 35097711
how do I call this function
LVL 15

Expert Comment

ID: 35097732
$newdate = add_date(curdate(),4)
echo format($newdate,'m/d/Y');

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

LVL 15

Accepted Solution

gplana earned 175 total points
ID: 35097745
sorry, there is a missing semi-colon (;) on my previou message. Please try this:

$newdate = add_date(curdate(),4)
echo format($newdate,'m/d/Y');
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 175 total points
ID: 35098893

$fourDaysHence = date("Y-m-d", strtotime("NOW +4 DAYS") );


$fourDaysHence = date("m/d/Y", strtotime("NOW +4 DAYS") );

See for different ways to lay out the resulting date


Author Closing Comment

ID: 35099411

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

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.
The viewer will learn how to count occurrences of each item in an array.
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.

705 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