Adding minutes to date time not working properly

前端 未结 1 503
予麋鹿
予麋鹿 2020-12-22 13:45

I am working on Yii2. In it I am trying to insert data into 3 different stages. i.e. I am using 3 queries one by one to insert different types of data. The data

相关标签:
1条回答
  • 2020-12-22 14:07

    customize this:

    $dt = date('Y-m-d H:i:s');
    echo $dt . '<br>'; //now
    $min5Later = strtotime('+5 minutes', strtotime($dt));//5 min later from $dt
    $min5LaterFormat = date('Y-m-d H:i:s', $min5Later);
    
    $min10Later = strtotime('+10 minutes', strtotime($dt));//10 min later from $dt
    $min10LaterFormat = date('Y-m-d H:i:s', $min10Later);
    
    $min15Later = strtotime('+15 minutes', strtotime($dt));//15 min later from $dt
    $min15LaterFormat = date('Y-m-d H:i:s', $min15Later);
    
    for ($i = 0; $i <= 2; $i++) {
        $min5Later = strtotime('+5 minutes', strtotime($min5LaterFormat));//5 min later from $min5later
        $min5LaterFormat = date('Y-m-d H:i:s', $min5Later);
        $min10Later = strtotime('+10 minutes', strtotime($min10LaterFormat));//10 min later from $min10later
        $min10LaterFormat = date('Y-m-d H:i:s', $min10Later);
        $min15Later = strtotime('+15 minutes', strtotime($min15LaterFormat));//15 min later from $min15later
        $min15LaterFormat = date('Y-m-d H:i:s', $min15Later);
    
     echo $min5LaterFormat . ' | ';
     echo $min10LaterFormat . ' | ';
     echo $min15LaterFormat . ' | <br>';
    }
    

    output:

    2020-05-10 19:19:47
    2020-05-10 19:29:47 | 2020-05-10 19:39:47 | 2020-05-10 19:49:47 |
    2020-05-10 19:34:47 | 2020-05-10 19:49:47 | 2020-05-10 20:04:47 |
    2020-05-10 19:39:47 | 2020-05-10 19:59:47 | 2020-05-10 20:19:47 |
    
    0 讨论(0)
提交回复
热议问题