Re: Postgres Date Type Value

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michael Arnold <myk321(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Postgres Date Type Value
Date: 2022-12-18 00:20:50
Message-ID: 89384.1671322850@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michael Arnold <myk321(at)gmail(dot)com> writes:
> Something like this:

> int32_t date_val = be32toh(*((uint32_t *) PQgetvalue(res, 0, 17)));

> Gives date_val=1,466,004,328 for 2022-10-25.

The origin is 2000-01-01 (I'm pretty sure that's documented somewhere),
so the correct integer value for that date is 8333 by my math.

Looking at the bit-pattern for 1,466,004,328: 0x57617368, it seems
totally unrelated, more like ASCII text ("Wash") than anything else.
You sure you're reading the right column of the result?

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2022-12-18 00:24:21 Re: Postgres Date Type Value
Previous Message Michael Arnold 2022-12-17 23:55:16 Postgres Date Type Value