Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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.

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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

1 Reply
Anonymous
Not applicable
Author

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));