Getting date/time according to user time for PostgreSQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
yisheng
Forum Newbie
Posts: 8
Joined: Wed Jul 25, 2007 10:34 pm
Location: Singapore

Getting date/time according to user time for PostgreSQL

Post by yisheng »

Hi,

I'm trying to retrieve and displaying date and time of post according to user timezone.
Such as this forum showing the date and time of post.

I have done this in MySQL before -

Code: Select all

SELECT CONVERT_TZ(NOW(), sometable.server_time, sometable.user_time) AS user_time_now FROM sometable
Is there a way to do this in PostgreSQL?

Thanks in advance.
yisheng
Forum Newbie
Posts: 8
Joined: Wed Jul 25, 2007 10:34 pm
Location: Singapore

Post by yisheng »

Ok, i just found this

Code: Select all

SELECT (NOW() + justify_interval(interval '+1 hour') - justify_interval(interval '+4 hour')) FROM sometable
Asumming +1 hour is user timezone and +4 hour is server timezone.

Is this a good way to retrieve user time?
Post Reply