Using truncate function in PostgreSQL

amna

New member
How to truncate day of month in PostgreSQL?
Like, I am trying to truncate
DATE_TRUNC('dom' , column_name) but it gives error.
 
Solution
How to truncate day of month in PostgreSQL?
Like, I am trying to truncate
DATE_TRUNC('dom' , column_name) but it gives error.
In PostgreSQL, the abbreviation for "day of month" is not "dom". Instead, it is "day". You can truncate the day of the month from a date column in PostgreSQL using the following syntax:

scss:
DATE_TRUNC('day', column_name)

For example, if you have a table called "my_table" with a date column called "my_date_column", you can truncate the day of the month from that column like this:

sql:
SELECT DATE_TRUNC('day', my_date_column) FROM my_table;

This will return a result set with all the dates in the "my_date_column" column truncated to the first day of the month.

John

New member
How to truncate day of month in PostgreSQL?
Like, I am trying to truncate
DATE_TRUNC('dom' , column_name) but it gives error.
In PostgreSQL, the abbreviation for "day of month" is not "dom". Instead, it is "day". You can truncate the day of the month from a date column in PostgreSQL using the following syntax:

scss:
DATE_TRUNC('day', column_name)

For example, if you have a table called "my_table" with a date column called "my_date_column", you can truncate the day of the month from that column like this:

sql:
SELECT DATE_TRUNC('day', my_date_column) FROM my_table;

This will return a result set with all the dates in the "my_date_column" column truncated to the first day of the month.
 
Solution
Top