Set hour in a variable type Date

Hi,
I have a variable type Date, called “sendDate” with the value 2020-10-07T13:00:00
Now I wish to update this variable and set a fixed hour (for example 19:00)
So, the new value will be 2020-10-07T19:00:00
How can I solve it?

Thanks

@glonico refer this example:

you can use expression like below:

${dateTime().withMillis(sendDate.getTime()).plusHours(4).toDate()}

You can find more date related functions here:

http://joda-time.sourceforge.net/api-release/org/joda/time/DateTime.html

1 Like

Hi,
this example is not valid in my case, because I don’t have an initial reference time established, but in some cases I could also subtract hours.
For example, the starting variable could be 2020-10-07T13:00:00 but it could also be 2020-10-07T22:00:00.
So, I wish to obtain a value such as 2020-10-07T19:00:00 regardless of the starting value.

Thanks

Hello @glonico, as @aravindhrs pointed out you should have a look into Joda API. You could use withTime(…) method.

Best, McAlm

Hi @McAlm and @aravindhrs
I solve it with this script:
Date newDate = (Date) execution.getVariable(“sendDate”);
newDate.setHours (19);
newDate.setMinutes (00);
execution.setVariable (“sendDateNew”,newDate);

Thanks