Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgres sql, date_trunc without extra zeroes

This is an excerpt from my sql query

SELECT
date_trunc(
    'day',
    to_timestamp(requests.date_created)
)AS DAY,

this is my output 2013-02-04 00:00:00+00

I want this to be just 2013-02-04

how do I get the desired result?

like image 514
CQM Avatar asked Feb 04 '13 16:02

CQM


People also ask

What is Date_trunc in PostgreSQL?

In PostgreSQL, DATE_TRUNC Function is used to truncate a timestamp type or interval type with specific and high level of precision. Syntax: date_trunc('datepart', field) The datepart argument in the above syntax is used to truncate one of the field,below listed field type: millennium. century.

What is the format of timestamp in PostgreSQL?

Postgres DATE data type Postgres uses the DATE data type for storing different dates in YYYY-MM-DD format. It uses 4 bytes for storing a date value in a column. You can design a Postgres table with a DATE column and use the keyword DEFAULT CURRENT_DATE to use the current system date as the default value in this column.

What does Epoch mean in PostgreSQL?

Posted on 28th September 2022. YES, you can convert EPOCH to Timestamp by merely switching to the present Timestamp in PostgreSQL DBMS. EPOCH time is nothing but the number of seconds from 00:00:00 UTC on 1 January 1970. Till date, without adding the extra leap year days, this is considered.


1 Answers

please, try

SELECT date_trunc(...)::date;
like image 75
Pavel Stehule Avatar answered Nov 05 '22 07:11

Pavel Stehule