<?php

/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 16/7/24
 * Time: 下午6:25
 */
class date_helper
{
    static public function diff_days(DateTime $a,DateTime $b)
    {
        if($a->getTimestamp() < $b->getTimestamp()) {
            return false;
        }
        else {
            $interval = $a->diff($b);
            return $interval->days;
        }
    }

    static public function sub_days($time,$days)
    {
        $date = new DateTime();
        $date->setTimestamp($time);
        $date->setTime(0,0,0);
        $ret = $date->sub(new DateInterval("P{$days}D"));
        return $ret->getTimestamp();
    }
}

