Logo Questions Linux Laravel Mysql Ubuntu Git Menu

PHP date to string conversion is adding a minute to each result

I'm currently trying to display a 'time' entry from my database in PHP, and for some strange reason, it's displaying the time + 1 minute.

The entry is


And when my PHP code

$schedule = DB::table('event_sessions')->get();
foreach $schedule as $session {
    echo date( 'g:m A', strtotime($session->start_time)

it is displaying as

9:01 AM

Is there some configuration that might be wrong? I am using the Laravel framework and MySQL.

like image 747
cchapman Avatar asked Mar 17 '23 10:03


1 Answers

Because m is for the month in the date() function! (So if you want to use Minutes use i (e.g. echo date( 'g:i A', strtotime("09:34")); -> 09:34 AM))

You also can do this:

echo date( 'g:m A', strtotime("09:34"));

And the return is:

09:01 AM

See the manual here for the date() function: http://php.net/manual/en/function.date.php

An a quote from the manual:

m Numeric representation of a month, with leading zeros 01 through 12

like image 146
Rizier123 Avatar answered Mar 26 '23 01:03