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!
Community Manager

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.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Put Massive Amounts of Data to Work

Learn how to make your data more available, reduce costs and cut your build time

Watch Now

How OTTO Utilizes Big Data to Deliver Personalized Experiences

Read about OTTO's experiences with Big Data and Personalized Experiences

Blog

Talend Integration with Databricks

Take a look at this video about Talend Integration with Databricks

Watch Now