Server timestamp

Started by Chris Bartlettalmost 17 years ago3 messagesgeneral
Jump to latest
#1Chris Bartlett
c.bartlett@paradise.net.nz

Date and time functions like current_time return the client machine's
time. Is there a way of getting the database server's time? I have a
situation that requires comparison of a date stamp on records with
"today", but I need to avoid the possibility of a user changing their
computer's clock time.

#2Scott Marlowe
scott.marlowe@gmail.com
In reply to: Chris Bartlett (#1)
Re: Server timestamp

On Sun, May 3, 2009 at 7:04 AM, Chris Bartlett
<c.bartlett@paradise.net.nz> wrote:

Date and time functions like current_time return the client machine's time.
Is there a way of getting the database server's time? I have a situation
that requires comparison of a date stamp on records with "today", but I need
to avoid the possibility of a user changing their computer's clock time.

I think you're confused. According to the docs:

CURRENT_TIME and CURRENT_TIMESTAMP deliver values with time zone;
LOCALTIME and LOCALTIMESTAMP deliver values without time zone.

The time delivered is the server's time, adjusted to client's
timezone. If you want the server time without timezone then use
localtime / localtimestamp.

It's never the client's time.

#3Craig Ringer
craig@2ndquadrant.com
In reply to: Chris Bartlett (#1)
Re: Server timestamp

Chris Bartlett wrote:

Date and time functions like current_time return the client machine's
time.

Er, no they don't. They return the server's time, adjusted to the
client's time zone if the client specified its time zone using SET TIMEZONE.

At least, that's how they behave here, and I can't imagine any sane
client interface attempting to change it.

--
Craig Ringer