1

Is there a better way to get local time to the second in PostgreSQL than this?

Set timezone= 'America/New_York';
Select to_char(current_timestamp, 'MM/DD/YYYY HH24:MI:SS') As EasternCurrentTime;

We do a lot of these in different places for logging within our ETL and would like to do it on one line.

1
  • You could abstract it into a postgres function so at least its just a one-liner and compartmentalized to the current thread/query Commented Sep 28, 2018 at 16:30

1 Answer 1

1

I'd suggest

SELECT to_char(current_timestamp AT TIME ZONE 'America/New_York',
               'MM/DD/YYYY HH24:MI:SS');
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for that (though I think we're not supposed to post these)
Nobody will complain as long as you don't write it as an answer. The preferred way to express thanks is upvoting and/or accepting the answer.

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.