Obliczanie różnicy czasu i obliczanie nowej daty

error_reporting(E_ALL ^ E_WARNING ^ E_PARSE ^ E_NOTICE);
//date_default_timezone_set ("PL/PL");
date_default_timezone_set ("Europe/Warsaw");

class date_check {
static public function check_on($data) {
$day_ts = 86400;

$date_order = $data['date_order'];
$roznica = (strtotime($date_order)-strtotime(date('Y-m-d')));

$roznica_day = floor($roznica/$day_ts);

echo $date_order."\n";
echo $roznica."\n";
echo $roznica_day."\n";

if($roznica_day<12) {

$date_start = date('Y-m-d', strtotime("1 day"));
$date_stop = date('Y-m-d', strtotime("21 day"));

} else {

$day_back = -10;
$day_next = 10;

$date_start = date('Y-m-d', strtotime($date_order." ".$day_back." day"));
$date_stop = date('Y-m-d', strtotime($date_order." ".$day_next." day"));
}

return array('date_start'=>$date_start, 'date_stop'=>$date_stop);
}
}

$data_back = date_check::check_on(array('date_order'=>'2016-04-18'));

echo $data_back['date_start']."\n";
echo $data_back['date_stop']."\n\n";

$data_back = date_check::check_on(array('date_order'=>'2016-04-11'));

echo $data_back['date_start']."\n";
echo $data_back['date_stop']."\n\n";

$data_back = date_check::check_on(array('date_order'=>'2016-04-26'));

echo $data_back['date_start']."\n";
echo $data_back['date_stop']."\n\n";

Wynik działania:

2016-04-18
-777600
-9
2016-04-28
2016-05-18

2016-04-11
-1382400
-16
2016-04-28
2016-05-18

2016-04-26
-86400
-1
2016-04-28
2016-05-18

Obliczanie różnicy czasu

echo (strtotime("2009-09-14 15:55:00")-strtotime("2009-09-14 11:00:02"));
$hour_ts = 3600;
$day_ts = 86400;
$modif_ts = strtotime("-10 day");
$modif_ts = strtotime("-4 hours");
$modif = strtotime("2009-09-14 15:55:00");
$modif_ts = strtotime($modif);
$now_ts = time()+1;
$d_ts = $now_ts-$modif_ts;
echo $d_ts .'';

Dodanie do daty akutalnej godziny

echo date('H:i:s', strtotime('now')) . ' ';
echo date('Y-m-d', strtotime("+2 days")) . ' ' . date('H:i:s', strtotime('now')) . '';
$task_dateend = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime("+2 days")) . ' ' . date('H:i:s', strtotime('now'))));
echo $task_dateend;

Wynki:
2009-07-25 14:02:51

Losowanie daty

 echo date(‚Y-m-d h:i:s’, strtotime („2008-01-01 +”.rand(1,60).”days „.rand(1,23). ” hours „.rand(1,59).” minutes „.rand(1,59).” seconds”)), „<br>”;