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

[resolved] HELP - HOW TO CHANGE DATE FORMAT

Hi all,
I face a problem, i test a solution that i mean good but i don't know why it result error in tMap
I have a date in this format MM/DD/YYYY  so i want to get in the output of my tMAP the same date in this format DD/MM/YYYY
So i do this transformation in my tMap:
TalendDate.parseDate("dd/MM/yyyy",  TalendDate.formatDate("MM/dd/yyyy",row2.Date_debut_arret_travail) )
But it does not work, may somebody help me please?
Thanks,
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

if you want date in different format in tMap then use schema to mention desire output format. 
once you convert date, then change the output date format in schema column to "dd/MM/yyyy" Talend will do all the stuff for you. you don`t need to write anything else. 
If you want to use formatted date in same column then you need to do two time parsing for same date. 
first convert string to date using actual format then use 
TalendDate.parseDate("dd/MM/yyyy", TalendDate.formatDate("dd/MM/yyy", TalendDate.parseDate("MM/dd/yyyy","10/20/2015")))

Hope this will help you..

View solution in original post

9 Replies
Anonymous
Not applicable
Author

Hi,
 
Here is a tConvertType component which helps to automatically convert one Talend java type to another and thus avoid compiling errors.

Best regards
Sabrina
Anonymous
Not applicable
Author

Hi 
Try with below expression:
TalendDate.parseDate("dd/MM/yyyy",TalendDate.formatDate("dd/MM/yyyy",row2.Date_debut_arret_travail)) 
Regards,
kumar
Anonymous
Not applicable
Author

Hi kumar.talend,
Thank you for your response. I have tried it but it does not work.
This expression: TalendDate.formatDate("dd/MM/yyyy" , xxxx ) transform the date format to String so the pattern "dd/MM/yyyy"
should respect the date format
If my analysis is wrong, please feel free to correct me.
Thanks,
Anonymous
Not applicable
Author

if you want date in different format in tMap then use schema to mention desire output format. 
once you convert date, then change the output date format in schema column to "dd/MM/yyyy" Talend will do all the stuff for you. you don`t need to write anything else. 
If you want to use formatted date in same column then you need to do two time parsing for same date. 
first convert string to date using actual format then use 
TalendDate.parseDate("dd/MM/yyyy", TalendDate.formatDate("dd/MM/yyy", TalendDate.parseDate("MM/dd/yyyy","10/20/2015")))

Hope this will help you..
Anonymous
Not applicable
Author

Hi umershrakhe,
if you want date in different format in tMap then use schema to mention desire output format. 
once you convert date, then change the output date format in schema column to "dd/MM/yyyy" Talend will do all the stuff for you. you don`t need to write anything else.
I have done whate you recommand, but i get this error:
Exception in component tMap_2
java.lang.NullPointerException
at java.util.Calendar.setTime(Calendar.java:1106)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:955)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:948)
at java.text.DateFormat.format(DateFormat.java:336)
at routines.TalendDate.formatDate(TalendDate.java:130)

Thank for your help, any help please,
Anonymous
Not applicable
Author

before converting string to date check for nullability and empty, that`s way you are getting this error, also check whether your date has time associate or not, you can check it by printing date on console. 
Anonymous
Not applicable
Author

Hi umeshrakhe,
This is the structure of my tMap:
tMap inputRow                             ========>                 tMap otputRow
MM/dd/yyyy (data is already in date type)                  dd/MM/yyyy (tMap row is in date type)
So  to answer you my data to transform are not in string format, and are from a file that i have already cheak.
So i have not empty row and all date are in this format: MM/dd/yyyy
Thank for help, 
Anonymous
Not applicable
Author

Hi umeshrakhe,
You are right in your post number 5:
if you want date in different format in tMap then use schema to mention desire output format. 
once you convert date, then change the output date format in schema column to "dd/MM/yyyy" Talend will do all the stuff for you. you don`t need to write anything else.
I haved tried it first, it didn't work because the problem was in another side in the same tMap.
So i focus in this case thinking that it is my error.
Thank you all for help. 
Anonymous
Not applicable
Author

thank you for feedback.