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
https://forums.phpfreaks.com/topic/42700-mysql-calculate-difference-between-dates/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.