You are confusing dates and times with durations. Consider these two sentences:
- the movie starts at two o'clock in the afternoon
- the film lasted two hours
In the first, "two hours" refers to a time: a specific time of the day. In the second, "two hours" refers to the duration: the amount of time, unrelated to a specific time (it does not say what hours began or ended, it only says how long lasts).
What may be confusing is that they both use the same words ("hours", "minutes", etc.), but they are different concepts. A date represents a specific point in a calendar (day, month and year), and a time represents a specific time of a day. Already a duration is only a amount of time, and is not associated with a specific instant.
That said, strtotime('01:00:00')
creates a date (not a duration) for today, with the time set at 1 am:
echo date('Y-m-d H:i:s', strtotime('01:00:00')); // 2019-09-03 01:00:00
In fact strtotime
returns the timestamp corresponding to the date above, using the default Timezone that is configured in PHP.
If you want to add hours to a date, you can use the special formats which are accepted by strtotime
, which allows adding lengths to a date/time, for example + X hours
to add X hours. In this case, your string that corresponds to the length has hour, minute and second, then it would look something like this:
$data = '2019-09-23 12:30:00';
$duracao = '01:00:00';
$v = explode(':', $duracao);
echo date('d/m/Y H:i:s', strtotime("{$data} + {$v[0]} hours {$v[1]} minutes {$v[2]} seconds"));
I use explode
to break the string in hours, minutes and seconds (the values are in the array $v
). Then I mount the corresponding string, containing the date and using the syntax + duracao
to add the duration to the date.
The exit is:
23/09/2019 13:30:00
I think this php function might help you: https://www.php.net/manual/en/datetime.add.php
– Edward Ramos
Possible duplicate of Add days to a date
– novic