Search code examples
phplocalestrtotimedate-conversion

setlocale Format MySQL datetime with php


For some reason, it shows me incorrect minutes and hour, and month. It should show "October" and correct minutes and hour.

setlocale(LC_ALL, 'et');

$date = strtotime($row['date']);

echo date("d B Y H:i", mktime($date));

Solution

  • You should use strftime() instead of date(). (date() is not locale aware.)

    http://php.net/strftime

    And the mktime() is not needed. strtotime() already sets $date as a timestamp.