Reputation: 1405
I have the following PHP code on my local apache2 webserver on a Mac Book Pro using PHP 5.3.8 and Default timezone set to Europe/Zurich:
$now = time();
$in5min = $now + 300;
echo "now: " . date('H:m:s', $now);
echo "<br>in 5 min: " . date('H:m:s', $in5min);
echo "<br>now using date only: " . date('H:m:s');
Result looks like this (run at 18:16:12, 26 July 2012):
now: 18:07:01
in 5 min: 18:07:01
now using date only: 18:07:01
Note that I can refresh the page - the seconds change, the hours and minutes remain. So 5 minutes later it's still 18:07
.
What's wrong with my webserver settings? And why does the time calculation not work?
Upvotes: 1
Views: 176
Reputation: 1405
Haha could hit me in the face: date('H:m:s') is totally wrong. "m" is for month, not minutes. Use date('H:i:s') instead
Upvotes: 0
Reputation: 8767
You're using the wrong interval
, but I would suggest using DateTime::add
instead:
<?php
$date = date_create('2000-01-01');
date_add($date, date_interval_create_from_date_string('10 days'));
echo date_format($date, 'Y-m-d');
?>
Upvotes: 0
Reputation: 59699
The correct format string is i
for minutes, not m
. m
is for months.
date('H:i:s');
Upvotes: 12