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: 
ManjunathBhat
Contributor
Contributor

Adding Hours to existing UTC Timestamp

Hi All,

Can someone help me with a solution as Talend is pretty new to me.

Currently I am pulling data out of API where I have to pass todate and fromdate in UTC to limit the data being pulled.

I have a context variable "incremental_timestamp"  which gets the data from database ex format is 2024-02-09T17:00:56Z and this database value is fed through variable 

"incremental_timestamp_utc" = TalendDate.formatDateInUTC("yyyy-MM-dd", TalendDate.getCurrentDate())+"T"+TalendDate.formatDateInUTC("HH:mm:ss", TalendDate.getCurrentDate())+"Z"

Now I need to add exactly 4 hours to context variable

Ex NewPlus4hourvariable = "incremental_timestamp" + 4 hours and result should be 2024-02-09T21:00:56Z

Does this work?

NewPlus4hourvariable = "incremental_timestamp" + MakeTime(4,0) does this give me 2024-02-09T21:00:56Z ?

If not how can I achive this? 

Any help much appreciated. 

Labels (2)
1 Reply
BraidwoodIT
Contributor II
Contributor II

Hi there, you can use Talend.addDate to add the 4 hrs. I'm not sure exactly what you are doing but you can format the current date straight into the UTC format. Also, if you need it in local timezone there are options for that too. No need to build the date and time separately I think.

try using TalendDate.formatDateInTimeZone("yyyy-MM-dd'T'HH:mm:ss'Z'",varDate,"Australia/Sydney"))

where varDate is the UTC date you are working with. To add to a date (or subtract) you can use something like this:

TalendDate.addDate(row8.enddate,"yyyy-MM-ddT",-1,"dd")

which subtracts a day from the date part of row8.enddate. You would need to modify the date format to suit your data, and change dd to HH. Take a look at the help for the function, here's a snippet below:

 

add number of day, month ... to a date (with Date given in String with a pattern)

@param date (a Date given in string)
@param pattern (the pattern for the related date)
@param nb (the value to add)
@param dateType (date pattern = ("yyyy","MM","dd","HH","mm","ss","SSS" ))
@return a new date

Hope that helps

Andrew