LoginSignup
0
0

More than 5 years have passed since last update.

PHPのDateTimeに足し算引き算できる関数

Last updated at Posted at 2017-07-28

特定のDateTimeに1年足したりとか、5時間引いたりとか。

    /**
     *
     * @param DateTime $src_datetime
     * @param String $sign '+' or '-'
     * @param int $amount
     * @param String $unit 'days','hours'...
     * @return \DateTime
     */
    protected static function calc_time($src_datetime, $sign, $amount, $unit)
    {
        $dist_datetime = $src_datetime->modify($sign . $amount . ' ' . $unit);

        return $dist_datetime;
    }
0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0