How to Subtract Minutes

后端 未结 12 974
情书的邮戳
情书的邮戳 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:32
    //To Get Current DateTime
    $currentDate = date("Y-m-d H:i:s");
    
    //To Get Current DateTime - 15Min
    $oldDate = date("Y-m-d H:i:s", strtotime($currentDate) - (15 * 60));
    
    echo $currentDate;
    echo $oldDate;
    
    0 讨论(0)
  • 2020-12-15 16:33

    You can also use DateInterval object

    <?php
        $date = new DateTime('Y-m-d H:i:s');
        $date->sub(new DateInterval('PT10H30S'));
        echo $date->format('Y-m-d H:i:s');?>
    
    0 讨论(0)
  • 2020-12-15 16:37

    You can use DateInterval

    $date = new DateTime();
    $interval = new DateInterval("PT15M");
    $interval->invert = 1;
    $date->add($interval);
    echo $date->format("c") . "\n";
    
    0 讨论(0)
  • 2020-12-15 16:39

    Following is the way you can add days / hours / minutes / sec to current time

      $addInterval = date('Y-m-d H:i:s', strtotime("+$days days $hours hours $minute minute $sec second", strtotime(currentTime)));
    
    0 讨论(0)
  • 2020-12-15 16:40

    echo date('Y-m-d H:i:s', strtotime('-15 minutes'));

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

    you can try this as well,

    $dateTimeMinutesAgo = new DateTime("15 minutes ago");
    $dateTimeMinutesAgo = $dateTimeMinutesAgo->format("Y-m-d H:i:s");
    
    0 讨论(0)
提交回复
热议问题