All Forums Database
dlabar 5 posts Joined 06/11
22 Jan 2013
Number of seconds elapsed since beginning of day

I have a timestamp with time zone field and I would like to get the number of seconds that have elapsed from the start of that day.  This seems like it should be very trivial but I've searched for hours and tried many things that don't work.  What is a simple method for getting the number of seconds?

dnoeth 4628 posts Joined 11/04
22 Jan 2013

The number of seconds is
extract(hour from ts) * 3600 + extract(minute from ts) * 60 + extract(second from ts)
Dieter

Dieter

dlabar 5 posts Joined 06/11
23 Jan 2013

Thanks Dieter.  I was thinking there would be a way to do it in one `cast` instead of three `extract`s, but it probably doesn't matter and this works fine.

You must sign in to leave a comment.