471,073 Members | 1,328 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Previous MONTHNAME

Hey all,
I have a query that pulls data based on the month. I'm using
MONTHNAME(CURDATE()) to get the current month. I need to get the
previous month. Is there a way to do this using MONTHNAME?
thanks in advance
Jul 23 '05 #1
1 3380
"Wharfrat" <wh********@comcast.net> wrote in message
news:As********************@comcast.com...
Hey all,
I have a query that pulls data based on the month. I'm using
MONTHNAME(CURDATE()) to get the current month. I need to get the
previous month. Is there a way to do this using MONTHNAME?
thanks in advance


No! You don't use MONTHNAME() to calculate what the previous month was. To
do that you want to subtract a month from the current month is. The month
before this one can always be determined by:

SELECT DATE_ADD(CURDATE(), INTERVAL -1 MONTH)

And if you want to see it as a name instead of a number you can enclose that
calculation with MONTHNAME() :

SELECT MONTHNAME(DATE_ADD(CURDATE(), INTERVAL -1 MONTH))

Thomas Bartkus
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Marcel | last post: by
4 posts views Thread by Abraham Andres Luna | last post: by
4 posts views Thread by Bob | last post: by
24 posts views Thread by Ian Rastall | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.