Postgresql How extract date

133 Views Asked by At

I need get only the date from now() at my time zone, I have this query:

SELECT now() AT TIME ZONE 'America/Santiago'

And I'm getting something like this "2015-06-08 23:59:34.142569" but I need extract only the date, how can I get it? Thanks.

2

There are 2 best solutions below

1
On BEST ANSWER

If you want the server's date,

SELECT current_date;

If you need the date for any timestamp, eg the one you've gotten into your timezone, use date().

SELECT date(now() AT TIME ZONE 'America/Santiago');

Docs: http://www.postgresql.org/docs/current/static/functions-datetime.html

0
On

For postgres you want

select current_date;

if you need to extract any of those fields out of the returned value you can use extract

EXTRACT (field FROM source)