From: | Thad Humphries <thad(at)mindwrap(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | date conversions |
Date: | 2002-10-09 15:56:40 |
Message-ID: | 1034179000.1175.142.camel@opus |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
I'm porting some dynamic SQL code from another databases and need to
know how PostgreSQL handles this. I have looked at utils/date.h,
utils/datetime.h, and utils/timestamp.h but I don't understand which to
use or how. Can anyone help?
My database used 'timestamp without time zone'. My application's format
(how date-time will be passed in and out) is
typedef struct {
short year;
short month;
short day;
short hour;
short minute;
short second;
} DateStamp;
In Informix, for example, to convert between DateStamp and Informix
dtime_t I use (less input/error checking):
void
ds2dt( ds, dt )
DateStamp *ds;
dtime_t *dt;
{
char buf[26];
sprintf( buf, "%4.4hd-%2.2hd-%2.2hd %2.2hd:%2.2hd:%2.2hd",
ds->year, ds->month, ds->day,
ds->hour, ds->minute, ds->second );
dtcvasc( buf, dt );
}
/* and */
void
dt2ds( dt, ds )
dtime_t *dt;
DateStamp *ds;
{
char buf[26];
memset( (char *) ds, 0, sizeof *ds );
sscanf( buf, "%4hd-%2hd-%2hd %2hd:%2hd:%2hd",
&ds->year,
&ds->month,
&ds->day,
&ds->hour,
&ds->minute,
&ds->second );
}
What's the way to do this in PostgreSQL?
--
------------------------------------------------------------------------
Thad Humphries "...no religious test shall ever be required
Web Development Manager as a qualification to any office or public
Phone: 540/675-3015, x225 trust under the United States." -Article VI
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Ray | 2002-10-09 20:08:51 | Setting up PAM authentication |
Previous Message | Sudheesh Krishnankutty | 2002-10-09 05:30:01 | How to store encrypted data into database |