12Answers
  • 4
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How to Subtract Minutes

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 the current time.

here is my code so far (doesn't work):

$days   = date("j",time());
$months = date("n",time());
$years  = date("Y",time());
$hours  = date("G",time());
$mins   = (date("i",time()));
$secs   = date("s",time());
$mins   = $mins-15;
php

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);
  • 44
Reply Report

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)));
  • 4
Reply Report

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
Reply Report
//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;
  • -1
Reply Report
    • Is there any good reason to duplicate the existing answers? And why don't you use DateTime for this, providing a more readable code?

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions