Solved

current date+4 days

Posted on 2011-03-10
6
250 Views
Last Modified: 2012-06-27
current date+4 days
0
Comment
Question by:rgb192
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:gplana
Comment Utility
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.
 
<?php
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;
              }

?>
0
 

Author Comment

by:rgb192
Comment Utility
how do I call this function
0
 
LVL 15

Expert Comment

by:gplana
Comment Utility
$newdate = add_date(curdate(),4)
echo format($newdate,'m/d/Y');

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 15

Accepted Solution

by:
gplana earned 175 total points
Comment Utility
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');
0
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 175 total points
Comment Utility
Or

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

or

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

See http://uk.php.net/manual/en/function.date.php for different ways to lay out the resulting date

0
 

Author Closing Comment

by:rgb192
Comment Utility
thanks
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
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 …

772 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

12 Experts available now in Live!

Get 1:1 Help Now