How to truncate a date with time in postgresql?

2

Execute:

SELECT NOW()

and it appears to me:

'2017-08-07 10:53:44.207-06'

And I want to appear

'2017-08-07'
    
asked by Pedro Quiñonez 07.08.2017 в 18:55
source

2 answers

1

The option is to cast it with:

SELECT now()::date;
SELECT CAST(now() AS date);

Or you can just do one:

SELECT CURRENT_DATE

that brings the current date without time.

In the documentation there are more functions:

link

    
answered by 08.08.2017 / 00:39
source
2

The function now() returns an object of type timestamp with time zone . If you want to obtain only the part of the date, it is necessary to cast the data type date .

This can be done through:

SELECT CAST(now() AS date);

or with the following syntax, which is typical of PostgreSQL (it is not standard SQL)

SELECT now()::date;

More info about castings in PostreSQL here

    
answered by 07.08.2017 в 18:57