Sam Sam - 1 year ago 75
PHP Question

Simplest way to display current month/year in PHP like "Aug 2016"?

What is the shortest, simplest code to generate the curent month in Full English like

or short as three letter version like
and then add the current Year

So the code will, depending on the month and year, echo things like:

August 2016
Aug 2016

Answer Source

Full version:

<? echo date('F Y'); ?>

Short version:

<? echo date('M Y'); ?>

Here is a good reference for the different date options.


To show the previous month we would have to introduce the mktime() function and make us of the optional timestamp parameter for the date() function. Like this:

echo date('F Y', mktime(0, 0, 0, date('m')-1, 1, date('Y')));

This will also work (it's typically used to get the last day of the previous month):

echo date('F Y', mktime(0, 0, 0, date('m'), 0, date('Y')));

Hope that helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download