0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

○○分刻みの次回時間を計算

Last updated at Posted at 2022-11-21

15分刻みにしたときの次回の時間を計算。応用して分刻みの時刻表も可能

public function calc_datetime ($margin_minutes=15) {
    $timestamp = strtotime(date('Y-m-d H:i:s'));
//    $timestamp = strtotime(date('Y-m-d H:i:s', strtotime('2023-01-01, 00:00:00')));  時間指定する場合
    $year = date('Y', $timestamp);
    $month = date('m', $timestamp);
    $day = date('d', $timestamp);
    $hour = date('H', $timestamp);
    $minute = date('i', $timestamp);
    if($minute % $margin_minutes) {
      $minute += $margin_minutes - ($minute % $margin_minutes);
    } else {
      $minute += $margin_minutes;
    }
    $datetime = date('Y-m-d H:i:s', mktime($hour, $minute, 0, $month, $day, $year));
    return $datetime;
  }
0
0
4

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?