Talend Connect
Virtual Summit
JOIN US!
And visit the Customer
& Community Lounge.
May 27-28, wherever you are.

Change date format and get date from only month and year in string i.e. April 2011

Highlighted
Four Stars

Change date format and get date from only month and year in string i.e. April 2011

hi,

I want to change the date format from a string as my data provide only in month i.e. April 2011. Now I want to change it into date type also get the day.

If you can help me, I really appreciate it.

Thanks.


Accepted Solutions
Highlighted
Community Manager

Re: Change date format and get date from only month and year in string i.e. April 2011

Look at the code below. I have done exactly what you asked for with the assumption that you can use the 1st of the month as the day. I have hardcoded the month, year and day in this example. The code you are interested in (for a tMap, etc) is the line that starts "Date myDate = ". Essentially I am concatenating the date components and using a Java date format of "yyyy MM dd". Give it a try in a tJava and experiment with it.

 

String month = "July";
String year = "2012";

Date myDate = routines.TalendDate.parseDate("yyyy MMM dd", year+" "+month+" 01");

System.out.println(routines.TalendDate.formatDate("yyyy-MM-dd", myDate));

View solution in original post


All Replies
Highlighted
Community Manager

Re: Change date format and get date from only month and year in string i.e. April 2011

Look at the code below. I have done exactly what you asked for with the assumption that you can use the 1st of the month as the day. I have hardcoded the month, year and day in this example. The code you are interested in (for a tMap, etc) is the line that starts "Date myDate = ". Essentially I am concatenating the date components and using a Java date format of "yyyy MM dd". Give it a try in a tJava and experiment with it.

 

String month = "July";
String year = "2012";

Date myDate = routines.TalendDate.parseDate("yyyy MMM dd", year+" "+month+" 01");

System.out.println(routines.TalendDate.formatDate("yyyy-MM-dd", myDate));

View solution in original post

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog