expression to get the previous month from a date input in TOS

One Star

expression to get the previous month from a date input in TOS

I am mapping a Date column from Excel to Database. Date column in excel has the value 5/1/2016. When I map to a column in Database, it is translating as Sun May 01 00:00:00 MST 2016. The datatype for this column is varchar. From the date 5/1/2016, I want to get the previous month of the date and store that month value in the DB column. 
If the date is 5/1/2016 - the month should be "April"
If the date is 6/5/2016 - the month should be "May" and so on.
Is there a Talend expression that can do it? Can some one help me please?
Thanks in advance!
Sixteen Stars

Re: expression to get the previous month from a date input in TOS

It depends what you want. You could try using the "addDate" method. To subtract a month, you would just do this...
date = routines.TalendDate.addDate(date, -1, "MM");

But remember that you will need to know how you want to deal with dates such as "2016/10/31". If you take a month away from that, should you be left with "2016/09/30"? I'm not entirely sure how this would be handled by comparison to subtracting a month from "2016/05/13". Make sure to test these scenarios.