Add or subtract hours with date() function

I have a date stored in a database in the following format:
2023-04-06T18:23:15

What I need to do is take that date and add or subtract 8 hours from it so that I can pass a start and end date into my API, which requires that format above.

My attempts using the following to turn it into a number where I can add the time (a process described in a great tutorial from Dmitry elsewhere on the forums) are failing:
date([last_response],‘yyyy-MM-ddThh:mm:ss’)

Any help on how to do this would be much appreciated.

Hi @bmills313
According to the date function documentation, you should use HH instead of hh for "The hour, using a 24-hour clock from 00 to 23. "

Try using yyyy-MM-ddTHH:mm:ss for the date format parameter.
To add/subtract hours to the date, you should use the addhours function.

Gah! I completely screwed up the hh vs HH portion of the function. Thank you!

Also for reference, part of the reason why I kept it as-is is that the function below used in another step:
format(utctime(now()),‘yyyy-MM-ddThh:mm:ss’)

Generates this timestamp for me:
2023-04-10T04:36:19

And so I guess I just figured I could proceed with it, which was not the case.

Thanks, again, I think I can proceed forward from here!

1 Like