1

I have to update a timestamp in my database, but I want to change only the time, keeping the once registered date, for example, in '2021-10-07 11:00:00' I want to update it to '2021-10-07 10:00:00', how can I accomplish that?

the query I tried to run:

update p_bab.registro_ponto
set data_hora = timestamp::'10:00:00'
where id = 50;

1 Answer 1

11
update p_bab.registro_ponto
set data_hora = data_hora - interval '1 hour'
where id = 50;

if not and you have a constant time to set then :

update p_bab.registro_ponto
set data_hora = date(data_hora) + interval '10 hour'
where id = 50;

or

update p_bab.registro_ponto
set data_hora = date(data_hora) + '10:30:23'::time
where id = 50;
Sign up to request clarification or add additional context in comments.

3 Comments

So I can only opdate it with intervals? I can't set a specific hour?
@ThiagoSalgado see 3rd method
Oh, that's perfect, thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.