0

I am trying to convert a timestamp to interval & expecting an out of hh:mm only.

My code is like below

SELECT  to_timestamp('2020-01-10 08:00', 'YYYY-MM-DD hh24:mi')::timestamp without time zone 
        at time zone 'Asia/Calcutta' 
        at time zone 'Etc/UTC'

Actual purpose of the code is change the time zone into utc for a given date time value.

3
  • interval of what? seconds? microseconds? days? years? Commented Jan 13, 2020 at 10:38
  • Try this way: SELECT TIMESTAMP '2020-01-13 10:00:00' AT TIME ZONE 'Asia/Calcutta' AT TIME ZONE 'UTC'; Commented Jan 13, 2020 at 10:39
  • 2
    Interval is time/date difference and can thus not be a single time/date. Your code works, but interval has nothing to do with it. Maybe you need to rephrase your question? Commented Jan 13, 2020 at 10:41

1 Answer 1

2

It seems you are trying to get the timedifference (interval) between two timezones at a specific time.
This can be done like this for example:

SELECT  to_timestamp('2020-01-10 08:00', 'YYYY-MM-DD hh24:mi')::timestamp without time zone 
        at time zone 'Asia/Calcutta'
        -  
        to_timestamp('2020-01-10 08:00', 'YYYY-MM-DD hh24:mi')::timestamp without time zone 
        at time zone 'Etc/UTC'

This returns an interval = -05:30:00
You can of course convert it to hours and minutes with the to_char function, but that returns string, not interval.

Best regards,
Bjarni

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.