pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Returning an integer from a date
4+ messages / 3 participants
[nested] [flat]

* Returning an integer from a date
@ 1999-03-29 10:51  Rick Dearman <rdear@gameszone.net>
  0 siblings, 2 replies; 4+ messages in thread

From: Rick Dearman @ 1999-03-29 10:51 UTC (permalink / raw)
  To: pgsql-general@postgresql.org

I have a date field in a table, I want to create a function to
manipulate this date, however I want the date to come to me as an
integer.

Is this possible? Or do I have to get it as a char *string??



--
It said use Windows 95 or better, so I installed Linux!

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [GENERAL] Returning an integer from a date
@ 1999-03-29 11:22  Adriaan Joubert <a.joubert@albourne.com>
  parent: Rick Dearman <rdear@gameszone.net>
  1 sibling, 0 replies; 4+ messages in thread

From: Adriaan Joubert @ 1999-03-29 11:22 UTC (permalink / raw)
  To: rick@ricken.demon.co.uk; +Cc: pgsql-general@postgreSQL.org

Rick Dearman wrote:
> 
> I have a date field in a table, I want to create a function to
> manipulate this date, however I want the date to come to me as an
> integer.
> 
> Is this possible? Or do I have to get it as a char *string??
> 

Get it in a binary cursor and you can get it as a julian date (centred
around 2000). I handle all my dates as integers.

Adriaan



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [GENERAL] Returning an integer from a date
@ 1999-03-29 16:00  Herouth Maoz <herouth@oumail.openu.ac.il>
  parent: Rick Dearman <rdear@gameszone.net>
  1 sibling, 1 reply; 4+ messages in thread

From: Herouth Maoz @ 1999-03-29 16:00 UTC (permalink / raw)
  To: rick@ricken.demon.co.uk; pgsql-general@postgreSQL.org

At 12:51 +0200 on 29/03/1999, Rick Dearman wrote:


>
>   I have a date field in a table, I want to create a function to
>manipulate this date, however I want the date to come to me as an integer.
>
> Is this possible? Or do I have to get it as a char *string??

What kind of an integer do you need? You could have the "milliseconds since
epoch" kind of number quite easily. Or do you need a number such as
19990301?

Herouth

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





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [GENERAL] Returning an integer from a date
@ 1999-03-30 11:51  Herouth Maoz <herouth@oumail.openu.ac.il>
  parent: Herouth Maoz <herouth@oumail.openu.ac.il>
  0 siblings, 0 replies; 4+ messages in thread

From: Herouth Maoz @ 1999-03-30 11:51 UTC (permalink / raw)
  To: Rick Dearman <rick@ricken.demon.co.uk>; +Cc: 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





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~1999-03-30 11:51 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-03-29 10:51 Returning an integer from a date Rick Dearman <rdear@gameszone.net>
1999-03-29 11:22 ` Adriaan Joubert <a.joubert@albourne.com>
1999-03-29 16:00 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1999-03-30 11:51   ` Herouth Maoz <herouth@oumail.openu.ac.il>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox