Re: [GENERAL] Returning an integer from a date

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Rick Dearman <rick(at)ricken(dot)demon(dot)co(dot)uk>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Returning an integer from a date
Date: 1999-03-30 11:51:16
Message-ID: l03110709b32669184aa5@[147.233.148.140]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

At 22:18 +0200 on 29/03/1999, Rick Dearman wrote:

>
> I want the number of seconds since 1970

Basically, the function date_part( 'epoch', expression_of_datetime_type )
returns the number of seconds since 1970. But it returns a float, not an
integer, because datetimes can include milliseconds etc.

For example:

testing=> select date_part( 'epoch' , '1999-03-01 07:38:01.10'::datetime);
date_part
-----------
920266681.1
(1 row)

So, you may either write your program to expect a float there (float8), or
you can force it to be an integer using the function int() around the
date_part function. But then you lose the milliseconds.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ralf Weidemann 1999-03-30 13:27:28 sorting by date & time in descending order ??
Previous Message Rick Dearman 1999-03-30 07:47:14 User built functions?

Browse pgsql-sql by date

  From Date Subject
Next Message Herouth Maoz 1999-03-30 11:59:14 RE: [SQL] indexing a datetime by date
Previous Message Thomas Lockhart 1999-03-30 06:14:13 Re: [SQL] indexing a datetime by date