Vishal
Vishal

Reputation: 1492

Date format in Redshift create table

In Redshift create table command

 CREATE TABLE data
 (
    DATES   date,
    SHIPNODE_KEY    varchar,
    DELIVERY_METHOD varchar,
    NODE_TYPE   varchar,
    FULFILLMENT_TYPE    varchar,
    ORDERS  Integer
)

I need to set date format as yyyy/mm/dd but by default it is yyyy-dd-mm how can I specify date format?

Upvotes: 1

Views: 7093

Answers (1)

aaronsteers
aaronsteers

Reputation: 2571

The internal data format does not distinguish formatting, but you can use TO_DATE and TO_CHAR specify your preferred output format during INSERT or SELECT, respectively.

To modify the date format during SELECT:

SELECT TO_CHAR(DATES, 'YYYY/MM/DD'), * FROM data

To use the modified date format during INSERT:

INSERT INTO date (DATES /*... other columns here*/)
VALUES (TO_DATE('2016/12/01', 'YYYY/MM/DD' /* ... other values here*/)

Upvotes: 3

Related Questions