Santhosh Kumar N
Santhosh Kumar N

Reputation: 43

Converting from GMT to UTC

In a table all the records are stored in GMT time. But through my application i want to display only those records which falls into timezone UTC. i.e., in a web page i want to display only records that comes under UTC time zone.

Converting from GMT to UTC. Or Query the database to get all the records of UTC timezone.

I really appreciate an early reply.

I am using oracle database and application in PHP.

Upvotes: 0

Views: 1381

Answers (2)

I'll assume that your times are stored as DATE values, that all the values are stored as UTC times, and that the timezone you're interested in is constant. To convert from UTC to a given timezone you add the timezone's offset. In this case, since the timezone of interest has a negative offset you need to add in the same negative number. Thus, the following might be useful:

SELECT DATE_FIELD + INTERVAL '-5' HOUR
  FROM SOME_TABLE
  WHERE <whatever>

FWIW, there are some places where the conversion to local time uses a non-whole-hour offset - for example, Adelaide, Australia uses a +9.5 hour offset from GMT, and Kathmandu, Nepal uses +5.75 hours.

Share and enjoy.

EDIT: Given the data as you've described it, your best bet is probably to simply add in the session time zone, as follows:

SELECT your_gmt_timestamp_field AT TIME ZONE SESSIONTIMEZONE
  FROM your_table

Give this a try and see if it helps.

Upvotes: 0

Denis de Bernardy
Denis de Bernardy

Reputation: 78543

From Greenwich Mean Time on Wikipedia:

It [GMT] is arguably the same as Coordinated Universal Time (UTC).

Regarding converting, you can add/remove intervals, but in so far as I'm aware, Oracle supports timestamps with/without time zones:

select now() at time zone 'UTC' as utc,
       now() at time zone 'EST' as est,
       now() at time zone 'Europe/London' as london;

The last example, if it works, would allow you to not worry about daylight savings and so forth.

Upvotes: 1

Related Questions