27 Kwi 2016

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

16 Lip 2010

Sprawdzanie roku przestępnego

$get['year']='2010';
$get['year']='02';
$arr_month_days = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
$month_days=$arr_month_days[(int)$get['month']];
if($get['month']==2 && date('L',strtotime($get['year'].'-'.$get['month']))) {
$month_days=29;
}
18 Wrz 2009

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 .'';
23 Lip 2009

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