Skip to content

Instantly share code, notes, and snippets.

@kosinix
Created April 10, 2013 13:30
Show Gist options
  • Select an option

  • Save kosinix/5354637 to your computer and use it in GitHub Desktop.

Select an option

Save kosinix/5354637 to your computer and use it in GitHub Desktop.
Get month names using a for loop and PHP date function.
<?php
for($m=1; $m<=12; ++$m){
echo date('F', mktime(0, 0, 0, $m, 1)).'<br>';
}
@tibelchior

tibelchior commented Jan 21, 2019

Copy link
Copy Markdown

This is a great solution, but if you need locale it's better to use strftime.

<?php
$currentMonth = date('n');
setlocale(LC_ALL,"de_DE.UTF8");
for($m=$currentMonth; $m<=12; ++$m){
    $months[$m] = strftime('%B', mktime(0, 0, 0, $m, 1));
}

PS - this will return an array and will default the start to the current month.

@sergeliatko

Copy link
Copy Markdown

Thanks saved me time

@flaviosilveira

Copy link
Copy Markdown

Amazing!

@rizkhal

rizkhal commented Nov 1, 2020

Copy link
Copy Markdown

thanks!

@supersuryaansh

Copy link
Copy Markdown

Thanks

@dhimaskirana

Copy link
Copy Markdown

thank you..

@bhargav944

Copy link
Copy Markdown

I want month from April to march

@mureithimaina

Copy link
Copy Markdown

Save me some time, thanks

@pablim

pablim commented May 18, 2023

Copy link
Copy Markdown

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment