I have a row coming from mysql query like this:
$date=$row['date'];
In MySQL this date is stored like this:
2024-12-28 (Y-m-d)
I want to display this date in Swedish language like this:
28 Maj 2024
I am trying it like this:
setlocale(LC_ALL, 'sv_SE');
$date=$row['date'];
echo date_format($date,"d M Y");
But I get error DateTimeInterface, any idea how to achieve this?
>Solution :
Are you sure, $date is already an object?
You need to parse it first. Also date_format can not handle internationalization, you have to use IntlDateFormatter:
$row['date'] = '2024-5-28';
$cal = IntlCalendar::fromDateTime($row['date']);
echo IntlDateFormatter::formatObject($cal, "d MMMM Y", 'sv_SE');
will print
28 maj 2024
see the fiddle here: https://3v4l.org/NWRBj