Returning an integer from a date

Started by Rick Dearmanabout 27 years ago4 messagesgeneral
Jump to latest
#1Rick Dearman
rdear@gameszone.net

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!

#2Adriaan Joubert
a.joubert@albourne.com
In reply to: Rick Dearman (#1)
Re: [GENERAL] Returning an integer from a date

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

#3Herouth Maoz
herouth@oumail.openu.ac.il
In reply to: Rick Dearman (#1)
Re: [GENERAL] Returning an integer from a date

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

#4Herouth Maoz
herouth@oumail.openu.ac.il
In reply to: Herouth Maoz (#3)
Re: [GENERAL] Returning an integer from a date

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