Share on Google+Share on Google+

Mysql Date Previous Month

Mysql Date Previous Month is used to return the current and previous value of the month.

Mysql Date Previous Month


Mysql Date Previous Month is used to return the current and previous value of the month.

Understand with Example

The Tutorial illustrate an example that help you to describe Previous Month value. To understand this, we have a month (now( )) that return you current month value.

Query for finding current month:-




mysql> select month(now()) as CurrentMonth;


| CurrentMonth |
|           12 |
1 row in set (0.00 sec)

Query for finding Previous month:-

Once you are able to find the current month, you can easily find the previous month before the current month. The Query month(now( )) -1 return you the previous month value precede the current month.

month(now( ))-1 : The month(now( )) -1 return you the previous month  before the current month.

mysql> select month(now())-1 as PreviousMonth;


| PreviousMonth |
|            11 |
1 row in set (0.00 sec)



Posted on: June 15, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Mysql Date Previous Month  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
October 26, 2011
wrong way to do it

what if it is jan. then the answer will come 0
December 4, 2011
previous month

this has no point. it would work only for months greater than 1. if the current month is january it will display the previous month as 0 not 12. that doesnt make any sense
December 9, 2011
And what about January?

January is month number 1. So 1 - 1 = 0!!! MySQL will freak out
January 21, 2013
It doesn't work with end of year

This solution fails in January, as that is month 1 and minus 1 it is month 0 and not 12, being December.
June 12, 2012
get previous month in mysql

when the month is January it returns previous month as 0. how to get the previous month when selected month is january?