Re: extracting date from timestamp - Mailing list pgsql-novice

From Alexander Borkowski
Subject Re: extracting date from timestamp
Date
Msg-id 41F58F5C.1000707@abri.une.edu.au
Whole thread Raw
In response to extracting date from timestamp  ("Keith Worthington" <keithw@narrowpathinc.com>)
Responses Re: extracting date from timestamp
List 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

pgsql-novice by date:

Previous
From: "Keith Worthington"
Date:
Subject: extracting date from timestamp
Next
From: Tom Lane
Date:
Subject: Re: extracting date from timestamp