LoginSignup
0
0

More than 5 years have passed since last update.

PHPでDATETIME型のBETWEEN

Last updated at Posted at 2019-03-10

PHPでDATETIME型のBETWEEN用の範囲(境界値を含む)を作る例

$start_range = '2019-02-01 00:00:00';
$datetime = new DateTimeImmutable($start_range);

// 月
// "2019-02-28 23:59:59"
$end_range = $datetime->add(new DateInterval('P1M'))->sub(new DateInterval('PT1S'))->format('Y-m-d H:i:s');
// 年
// "2020-01-31 23:59:59"
$end_range = $datetime->add(new DateInterval('P1Y'))->sub(new DateInterval('PT1S'))->format('Y-m-d H:i:s');
0
0
0

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