Jump to content
We've recently updated our Privacy Statement, available here ×

Converting Month integer to Month Label (JAN)


dbranch

Recommended Posts

I have set my SQL statement to group invoices by month by using the month function, i.e  month(Date). This works fine and returns the month as an integer whenused as a field. I was wondering if anyone has written an expression to convert this integer into a month label, either as the month name or the three letter abreviation? Thanks.

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

try to use this in your textfield (class type String) expression:

$F{MONTH}.intValue()==1?"JAN":
    $F{MONTH}.intValue()==2?"FEB":
        $F{MONTH}.intValue()==3?"MAR":
            $F{MONTH}.intValue()==4?"APR":
                $F{MONTH}.intValue()==5?"MAY":
                    $F{MONTH}.intValue()==6?"JUN":
                        $F{MONTH}.intValue()==7?"JUL":
                            $F{MONTH}.intValue()==8?"AUG":
                                $F{MONTH}.intValue()==9?"SEP":
                                    $F{MONTH}.intValue()==10?"OCT":
                                        $F{MONTH}.intValue()==11?"NOV":"DEC";

 

______________________________
if it works... KARMA point please!    : ) 

Link to comment
Share on other sites

Hello,

I think the best way to resolve this problem is to create a table with month names and numbers, and join it. Something like this:

 

SELECT table1.field1, table1.field2, months.name

FROM table1 LEFT JOIN months on months.id=month(date)

Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...