0

Is there a way in PHP to print the month name and year in french when we have a number in this format 52013 or 42013 ?


I have tried:

$month = 42013;
$monthNr = substr($month, -5, 1);
$timestamp = mktime(0, 0, 0, $monthNr, 1);
$monthName = date('M', $timestamp );
echo $monthName;

but the result is Apr

I'd like to get Avril 2013

Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
Kirk ERW
  • 167
  • 1
  • 2
  • 14

1 Answers1

0

you could do something like a simple array of your month names

$months = array(1 => 'Janvier', 2 => 'Février'...);

Then just look up the month value

$monthName = $months[date('n', $timestamp )]; 

Or based on comments suggestion (this is based on the answer in the linked question)

setlocale(LC_ALL, 'fr_FR');

echo strftime('%B', $timestamp);
fullybaked
  • 4,117
  • 1
  • 24
  • 37