Re: extracting date from timestamp

From: Alexander Borkowski <alexander(dot)borkowski(at)abri(dot)une(dot)edu(dot)au>
To: KeithW(at)narrowpathinc(dot)com
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: extracting date from timestamp
Date: 2005-01-25 00:14:20
Message-ID: 41F58F5C.1000707@abri.une.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi Keith,

> I tried this
[...]
> SELECT CAST(extract(year from min(scan_timestamp)) || extract(month from
> min(scan_timestamp)) || extract(day from min(scan_timestamp)) AS date)
> INTO v_inventory_date
> FROM inventory.tbl_scanner;

You have the order for pl/pgsql SELECT INTO wrong (target variable(s)
first, then the value(s) you want to assign) and it is easier to get at
the information you want using the date_trunc function. Try

SELECT INTO
v_inventory_date
CAST(date_trunc('day', min(scan_timestamp)) AS date)
FROM inventory.tbl_scanner;

instead.

HTH,

Alex

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2005-01-25 00:29:57 Re: extracting date from timestamp
Previous Message Keith Worthington 2005-01-24 21:26:53 extracting date from timestamp