Skip to main content
Question

Remove hours from a timestamp (SQL)

  • September 29, 2023
  • 3 replies
  • 8 views

Hello guys,

I have this column MAX(TO_TIMESTAMP(LPAD("gb"."demat_entry_date", 19, '0'),'DD.MM.YYYY HH:MI:SS')) AS "date reception"

and i want to reduce the date by 2 hours.

 

Exemple :

From 2022-10-22 11:51:28 to 2022-10-22 09:51:28

 

I have tried a lot of formulas without success...

3 replies

Forum|alt.badge.img+14

Dear Antoine,

 

You could try something like an UTC offset:

MAX(TO_TIMESTAMP(LPAD("gb"."demat_entry_date", 19, '0'),'DD.MM.YYYY HH:MI:SS') AT TIME ZONE INTERVAL '2') AS "date reception"

 

Positive value subtracts hours from time, negative value adds hours.

 

https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/DataTypes/Date-Time/TIMEATTIMEZONE.htm?Highlight=with%20time

 

Yours,

Zsolt Borbely


Didn't work TIMESTAMPADD?

https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/Functions/Date-Time/TIMESTAMPADD.htm?tocpath=SQL%20Reference%20Manual%7CSQL%20Functions%7CDate%252FTime%20Functions%7C_____43

 

I am pretty sure I modified dates in SQL, but I no longer has access to a Celonis team to test it.

 

Best Luck!


  • Author
  • Level 4
  • October 2, 2023

Hello guys,

Yes it work perfectly, thanks you :)