Db:min and Db:max return only years on DateTime fields

Hi,

the title says it:
I try to get the oldest and the newest records in my MySQL database for website statistics.
The table is named “stats”, “zeit” is a DateTime field.

$myMin = Db::min('stats', 'zeit');
$myMax = Db::max('stats', 'zeit'));

dump($myMin); // -> 2023
dump($myMax); // -> 2024

The years are correct, but I need the complete dates and times.

I tried

dump(Db::query("SELECT MIN(zeit) AS anfang FROM stats"));

but this results in nothing …

When I query my database in phpMyAdmin I get the correct results.

The

return 'db' => [ ... ] 

declaration in config.php seems to be ok since all other queries (mostly Db::count() ) get the correct responses.

I’m using Kirby 4.1.0 and tried several MySQL / MariaDB installations.

Any advice?

This just returns a query object, so you have to do something here to fetch the row, e.g. first().

Min/Max don’t make sense, because they return a float therefore can only be used with numeric values.

1 Like