Print month given integer

Snippet

Sometimes you want to print a month without knowing the complete date (say, given 7 from the URL, you want July).

<?php 
 
print date('F', mktime(0, 0, 0, $month, 1));
 
// mktime(hour, minute, second, month, day, year)
// you don't care about the year.
 
$month = 6;
print date('F', mktime(0, 0, 0, $month, 1));
/*
 * outputs
 * June
 * for 6/1 at 12:00:00 am midnight
*/

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.