Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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));
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));