Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
mani1304
Creator
Creator

Date as context parameter type

Hi,

 

I want to get date as my context parameter, but when I do this, it changes it's format. e.g. my date is 07-17-2019, it changes this to Jul 17, 2019. May be this is because context date type doesn't have format in context parameter, can someone suggest how to achieve this. For the time, I am having all parameters in string  and later casting it to date.

Labels (2)
11 Replies
Anonymous
Not applicable

Hi,

 

    Since the context variable is date, it will retain the date value in it even though it changes format. So you will be able to safely use it for any date related operations like comparison.

 

    Now, if you want to print the date data of a context variable to a specific format, then you will have to convert them to string and use it accordingly.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

mani1304
Creator
Creator
Author

If I am getting it correctly, to print context parameter, it should be
string only or I am missing something.
E.g. I want to calculate start_date in prejob and later want to use it
several times, then first I have to convert it to string then cast it to
date because print can only be done in string ?
Anonymous
Not applicable

Hi,

 

     If you are doing date operations (like comparing two dates), then you do not have to worry about the format. But if you are using this value for String operations (like print the value in specified format), then you will have to convert the value to desired format of your choice.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

mani1304
Creator
Creator
Author

Means date can't be retain in it's derived form in date context parameter. Can we expect any improvement on this, so we needn't to take date as string ?
Anonymous
Not applicable

Hi,

 

     Please add the feature request using https://jira.talendforge.org.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

lennelei
Creator III
Creator III

When you say "it changes this to Jul 17, 2019", you mean for example if you print it?

 

In that case, you can force the format when printing the value :

System.out.println(TalendDate.formatDate("yyyy-MM-dd HH:mm:ss", context.myDate))

Please see SimpleDateFormat for details on the pattern.

 

Regards

mani1304
Creator
Creator
Author

Yes, I don't want to convert it to string and then print.
lennelei
Creator III
Creator III

I'm sorry but I don't get it.

 

Let's say you have a context variable myDate which is of a Date type.

 

If you want to print it:

System.out.println(TalendDate.formatDate("yyyy-MM-dd HH:mm:ss", context.myDate))

 

If you want to do calculation on it, use it directly:

Date newDate = TalendDate.addDate(context.myDate, "12", "dd")

This will add 12 days to your date and return a new Date object

 

If you want to insert it in a Date/Timestamp/whatever database column, you can use it directly in a tMap for example

If you want to insert it in a String database column, you will have to use TalendDate.formatDate() as well in your tMap

 

If you want to print it in a file, use it directly and choose a date format in the Talend schema definition

 

Could you please tell us exactly what you are trying to do because I really don't understand where the problem is?

 

Regards

mani1304
Creator
Creator
Author

What I want is like to print the date value, not after converting it to string then print.

System.out.println(context.myDate))

The reason for this is, let's take your example where 12 days are added in date and suppose I want to take this in my filename, e.g. test_context.parmdate.txt and here it changes it's format and I want to avoid this.

Hope this explains my concern.