Adding 1 hour to time variable

Adding 1 hour to time variable

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

Stefan Bogdanescu

Founder & Senior Architect

Adding an Hour to a Time String Without Losing Context

When working with temporal data in PHP, the distinction between a raw time string and a full timestamp is often the source of subtle bugs. Consider the scenario where you have a variable holding just the time of day, such as '10:09', and you need to add an hour to it. The immediate instinct might be to leverage strtotime(), which is undoubtedly one of PHP's most versatile functions for parsing dates and calculating offsets. However, there is a critical nuance in how strtotime() handles string inputs that explains why attempts like $time = strtotime('+1 hour') or $time = date('H:i', strtotime('+1 hour')) fail to produce the expected result when passed a simple time string directly.

The core issue lies in the input format. When you pass the string '10:09' into strtotime(), the function interprets it as a relative offset from the current Unix timestamp rather than an absolute point in time on the current day. In other words, PHP assumes you are asking "What is the date and time that is 10 hours and 9 minutes from now?" rather than "What time is it exactly at 10:09 AM today?". Consequently, adding +1 hour to that result yields a timestamp representing tomorrow or the next day, depending on the current time of execution, which breaks the logic of simply advancing the clock face by one hour.

To correctly add an hour to a standalone time string like '10:09', you must first establish a valid absolute timestamp for that specific day before applying the offset. The standard and most reliable approach involves reconstructing the full date context using date('Y-m-d'). By combining today's date with your time string, you create a format that strtotime() recognizes as an absolute moment in time.

Here is the correct implementation pattern:

$time = '10:09';
$today = date('Y-m-d'); // Gets current date, e.g., 2023-10-27
$absoluteTime = $today . ' ' . $time; // Creates "2023-10-27 10:09"
$newTimestamp = strtotime('+1 hour', strtotime($absoluteTime));

echo date('H:i', $newTimestamp); 
// Output: 11:09

In this sequence, strtotime($absoluteTime) converts the constructed string into a Unix timestamp representing today at 10:09. The second argument passed to the subsequent strtotime('+1 hour', ...) call anchors the calculation to that specific timestamp rather than the current system time. This ensures the math is performed strictly on the clock face, resulting in 11:09.

This distinction becomes particularly important when dealing with scheduled tasks or cron jobs where "now" might be irrelevant to your business logic. If you are building a scheduler that needs to trigger an event exactly one hour after 10:09 AM regardless of when the script runs, relying on relative offsets from date('c') or similar absolute functions without anchoring them to the base time will introduce drift errors.

While this manual reconstruction works perfectly in vanilla PHP, the Laravel ecosystem offers a more robust abstraction layer that abstracts away these timestamp manipulations entirely. Using Carbon, which is the de facto standard for date handling in modern Laravel applications, you can write code that reads like natural language and handles edge cases automatically. The syntax shifts from string concatenation to method chaining:

use Carbon\Carbon;

$time = '10:09';
$carbonInstance = Carbon::createFromTimeString($time);
$futureTime = $carbonInstance->addHour()->format('H:i');

echo $futureTime; // Output: 11:09

This approach handles daylight saving time transitions, timezone conversions, and leap seconds internally, reducing the risk of manual calculation errors. For developers maintaining legacy codebases or working in environments where Carbon is not available, the date() concatenation method remains the gold standard for precision. However, always verify that your input string adheres to a strict 24-hour format (HH:MM) to avoid ambiguity between AM and PM interpretations.

Our network