How to Subtract Minutes

How to Subtract Minutes

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

How to Subtract Minutes Without Breaking Your Logic

Subtracting a specific number of minutes from the current time might sound trivial, but it is one of those operations where a seemingly simple arithmetic mistake can break your entire logic flow. You cannot treat date("i") like a standard integer variable in PHP. The core issue with the code you posted isn't that subtracting 15 from $mins is mathematically wrong; it's that you are ignoring the relationship between minutes and hours.

When you execute $mins = $mins - 15;, the value of $mins might drop below zero. However, date("i") expects a value between 00 and 59. If your current time is 10:05 and you subtract 15 minutes, your variable becomes -10. While PHP handles negative integers fine in math, passing them back into date formatting functions or relying on them for further calculations often leads to unexpected results or empty strings depending on the specific function used next.

The robust solution involves manipulating the Unix timestamp directly. The strtotime() function is designed precisely for this: it understands natural language and arithmetic operations on time. You do not need to extract hours, minutes, seconds, days, or months just to adjust the minute component. Instead, take the current timestamp, subtract 900 seconds (15 minutes × 60), and format that new result.

$currentTimestamp = time();
$targetTimestamp = strtotime("-15 minutes", $currentTimestamp);
$formattedTime = date("Y-m-d H:i:s", $targetTimestamp);

This approach is superior because it handles the rollover automatically. If you are at 10:00 and subtract 20 minutes, the math 0 - 20 would be problematic if you were just manipulating integer components, but the timestamp arithmetic knows to roll back to 09:40 instantly. The strtotime() function acts as a translator between human-readable time strings and machine-readable integers, ensuring that hour boundaries and day boundaries are respected without manual conditionals.

If your goal is specifically to trigger a reminder email 15 minutes from now, you might actually want to add time rather than subtract it, depending on whether "subtract" means "past" or "future relative to now". If the requirement is strictly "send an email that happened 15 minutes ago", the subtraction logic holds. But if you are building a scheduler, calculating $nextSendTime = strtotime("+15 minutes") is the standard pattern.

When storing this calculated time for later use—perhaps in a database or a queue—you must stick to the Unix timestamp format. Storing formatted strings like "09:45" makes it incredibly difficult to perform subsequent calculations. If you need to subtract another 5 minutes from that stored value, you have to parse the string back into components, risking edge cases around midnight. Always store integers when doing time math; convert to human-readable format only at the point of display or logging.

In a Laravel application, you can leverage the now facade which provides a fluent interface for these operations. The Carbon package often included with Laravel simplifies this even further by treating dates as objects. You can create a new instance representing exactly 15 minutes in the past without worrying about the underlying integer math:

use Carbon\Carbon;

$reminderTime = Carbon::now()->subMinutes(15);
// $reminderTime is now an object ready for comparison or formatting

This object-oriented approach is often preferred in modern PHP ecosystems because it isolates the complexity of time arithmetic behind a clean API. You don't need to worry about whether your timestamp rollover worked correctly; the library handles the edge cases.

Whether you are using raw PHP or a framework, remember that time manipulation is rarely just about subtracting numbers from variables. It is about respecting the calendar structure. By working with timestamps and utilizing functions like strtotime or Carbon instances, you ensure your reminder logic remains robust across different time zones and daylight saving transitions without adding unnecessary complexity to your codebase.

Our network