Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
satyavar
Contributor III
Contributor III

TalendDate.getCurrentDate() in GMT

Hi
I am trying to update a date field using TalendDate.getCurrentDate() function in tMap but this one updates the field with local time zone. Is there a way to update the field in GMT?
Thanks
Kalyan
Labels (2)
8 Replies
Anonymous
Not applicable

The java Date object has non timezone. It is always UTC based. The timezone is actually only relevant if you want to render a date.
If you have a Date and you need to move it into GMT you have to know the necessary bias.
Use the function TalendDate.addDate:

TalendDate.addDate(TalendDate.getCurrentDate(), -1,"HH")

This example moves the current date one hour in the past.
Anonymous
Not applicable

Hi kalyan,
Try this expression  TalendDate.parseDate("dd MMM yyyy HH:mm:ss",TalendDate.getCurrentDate().toGMTString()) 
and let me know it's working for you or not.
Anonymous
Not applicable

I am not sure if the toGMTString method always returns the same format and it actually does not solve the problem because the parser depends also from the local timezone of the job server. I would not recommend that!
By far better is if you know which is the original timezone of the given date and move it with the correct bias.
satyavar
Contributor III
Contributor III
Author

Time zone varies between environments. I cannot write code specific to environments.
satyavar
Contributor III
Contributor III
Author

I tried the option of TalendDate.parseDate("dd MMM yyyy HH:mm:ss",TalendDate.getCurrentDate().toGMTString())

This works fine on output object if the action on data is set to Insert. But the same thing fails to load the date time in GMT if the action on data is set to Insert or update.
Any ideas?
Anonymous
Not applicable

can you please provide error on Insert or update action and also provide 1 sample date which you are trying to update.
Anonymous
Not applicable

Ok guys, it works fine? This method is deprecated! Oracle can remove this without any notification in the next Java release.
This is a quick and dirty solution and by far not professional.
satyavar
Contributor III
Contributor III
Author

Hi
Attached screenshot#1 has my job.
There are 2 if conditions.
Action on data is set to Insert only on final output (S_BU) object with If Condition 1.
Action on data is set to Insert or Update on final output (S_BU) object with If Condition 2.
If Condition 1 is true then date is getting stored correctly in GMT. But if 2nd condition is true then the 2 fields are getting stored in my local date time.
Why is such an odd behavior?
Thanks
Kalyan