Jump to content

[MySql] Calculate difference between dates


flaab

Recommended Posts

Hi 2 all =)

 

I've to build a function that tells me the resultant date from adding a number of days to a date.

 

Example:

 

function adddate(date, days) {

 

    return date + days;

 

}

 

For example if I call with this...adddate(2007-05-05, 5) it should give back a 2007-05-10.

 

I've tried but is hard! It should work with any number of days...

 

Thx. =)

 

 

Link to comment
Share on other sites


function adddate($date, $days) {
    list($year, $month, $day) = split("-", $date);

    //http://us2.php.net/manual/en/function.mktime.php
    //mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] ) 
    $time = (mktime(0,0,0,$month, $day, $year) + (60*60*24) * $days);
     return date("Y-m-d", $time);
}

 

--FrosT

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.