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