Previous MONTHNAME

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wharfrat

    #1

    Previous MONTHNAME

    Hey all,
    I have a query that pulls data based on the month. I'm using
    MONTHNAME(CURDA TE()) to get the current month. I need to get the
    previous month. Is there a way to do this using MONTHNAME?
    thanks in advance
  • Thomas Bartkus

    #2
    Re: Previous MONTHNAME

    "Wharfrat" <wharfrat95@com cast.net> wrote in message
    news:AsOdnXzqsd CIn0XfRVn-qQ@comcast.com. ..[color=blue]
    > Hey all,
    > I have a query that pulls data based on the month. I'm using
    > MONTHNAME(CURDA TE()) to get the current month. I need to get the
    > previous month. Is there a way to do this using MONTHNAME?
    > thanks in advance[/color]

    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(CURDAT E(), 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


    Comment

    Working...