How to Subtract Minutes

后端 未结 12 956
情书的邮戳
情书的邮戳 2020-12-15 15:48

I want to send a reminder email.I don\'t want to use cron on Linux/Unix/BSD box or Scheduled Tasks on Windows.

I\'m trying to subtract 15 minutes from t

相关标签:
12条回答
  • 2020-12-15 16:15

    To subtract 15 minutes from the current time, you can use strtotime():

    $newTime = strtotime('-15 minutes');
    echo date('Y-m-d H:i:s', $newTime);
    
    0 讨论(0)
  • 2020-12-15 16:15

    How about substracting the 15 minutes from time() before converting it?

    $time = time() - (15 * 60);
    

    And then use $time instead of time() in your code.

    0 讨论(0)
  • 2020-12-15 16:19

    Try using

    $min = time() - 900; //900 seconds = 15 minutes 
    
    0 讨论(0)
  • 2020-12-15 16:22
    $currentTime = date('Y-m-d H:i:s');
    $before15mins = strtotime('-15 minutes');
    echo date('Y-m-d H:i:s', $before15mins);
    
    0 讨论(0)
  • 2020-12-15 16:23

    Change the date into a timestamp (in seconds) then minus 15 minutes (in seconds) and then convert back to a date:

    $date = date("Y-m-d H:i:s");
    $time = strtotime($date);
    $time = $time - (15 * 60);
    $date = date("Y-m-d H:i:s", $time);
    
    0 讨论(0)
  • 2020-12-15 16:23

    To subtract 15 minutes you can do:

    date('Y-m-d H:i:s', (time() - 60 * 15));
    

    You can replace 15 with the number of minutes you want.

    In case you're looking to subtract seconds you can simply do:

    date('Y-m-d H:i:s', (time() - 10));
    

    In this way you'll subtract 10 seconds.

    0 讨论(0)
提交回复
热议问题