How to get date without time in PostgreSQL?

by wilmer.lemke , in category: PHP Databases , a year ago

How to get date without time in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by rollin , 9 months ago


To get the current date without the time in PostgreSQL, you can use the date_trunc function. For example:

SELECT date_trunc('day', current_timestamp);

This will return the current date with the time set to 00:00:00 (midnight).

If you have a timestamp column in a table and you want to select just the date part, you can use date_trunc in the SELECT statement like this:

SELECT date_trunc('day', timestamp_column) FROM table_name;

You can replace 'day' with 'month', 'year', or any other time unit to truncate the timestamp to that level of precision.

For example, to get the current month with the time set to the first day of the month at 00:00:00, you can use:

SELECT date_trunc('month', current_timestamp);