Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to change my timestamp into a date formatted as yyyy-01-01 in snowflake (sql)

I need to change a column of timestamps (date_col) to be formatted as yyyy-01-01. January first of the year in the date_col

Example:

actual                         desired

2021-04-02 00:00:00.000         2021-01-01
1966-05-04 00:00:00.000         1966-01-01

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Please use date_trunc

select date_trunc(year,'2021-04-02 00:00:00.000'::date);
+--------------------------------------------------+
| DATE_TRUNC(YEAR,'2021-04-02 00:00:00.000'::DATE) |
|--------------------------------------------------|
| 2021-01-01                                       |
+--------------------------------------------------+
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading