Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP date & strtotime adding 12 minutes?

Tags:

php

This code:

date_default_timezone_set('Europe/Stockholm');
$time = date('H:m', strtotime('08:00:00'));
echo $time;

Echoes 08:12... why? what am I missing here?

Tried also online at http://writecodeonline.com/php/ with exact this code and got same result. I would expect a error in hours, in case I made something wrong, but 12 minutes seems very strange.

The 08:00:00 value is a example from my database, all times are stored as TIME.

like image 323
Rikard Avatar asked Jun 11 '26 08:06

Rikard


1 Answers

In date format 'm' means month, not minutes. Try to use 'i'. For example:

$time = date('H:i', strtotime('08:00:00'));
like image 73
Pavel Tvaladze Avatar answered Jun 22 '26 16:06

Pavel Tvaladze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!