[resolved] HELP - HOW TO CHANGE DATE FORMAT

Five Stars

[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,

Accepted Solutions
Five Stars

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

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..

All Replies
Moderator

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

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
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

Hi 
Try with below expression:
TalendDate.parseDate("dd/MM/yyyy",TalendDate.formatDate("dd/MM/yyyy",row2.Date_debut_arret_travail)) 
Regards,
kumar
Five Stars

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

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,
Five Stars

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

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..
Five Stars

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

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,
Five Stars

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

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. 
Five Stars

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

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, 
Five Stars

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

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. 
Five Stars

Re: [resolved] HELP - HOW TO CHANGE DATE FORMAT

thank you for feedback.