1

In am trying to automatically account for timezone in my postgres query. My goal is to select records that are between 0:00 and 23:59 in EST or UTC - 5:00.

The current query only returns records between 0:00 and 23:59 in UTC time.

select path, start_time from routes where routes.network_id = 1 and routes.start_time between '2017-06-13 00:00:00'::timestamp AND '2017-06-13 23:59:59'::timestamp

the column start_time is a timestamp without timezone, so by default it is in UTC

SELECT pg_typeof("start_time") from routes limit 1;

returns timestamp without timezone

how would one write a query to account for 5 hours difference and convert start_time to UTC - 5?

1
  • this is in postgres Commented Jul 7, 2017 at 19:32

1 Answer 1

2

Try this:

select path, start_time - interval '5 hours' as start_time_est
  from routes
 where routes.network_id = 1 
       and routes.start_time between '2017-06-13 00:00:00-5'::timestamp  with time zone 
           AND '2017-06-13 23:59:59-5'::timestamp with time zone;
Sign up to request clarification or add additional context in comments.

Comments

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.