Home > database >  How to obtain MIN & MAX value of a Date Column for a given Month?
How to obtain MIN & MAX value of a Date Column for a given Month?

Time:12-01

I have a table with the Date Column containing several entries of Date for any given Day. I would like to print MIN(DATE) and MAX(DATE) for each day for the month of October 2021. Is there a way to obtain the necessary results as expected?

2021-10-30 00:00:00.000
2021-10-30 12:13:00.000
2021-10-30 17:19:00.000
...
...
2021-10-31 00:10:00.000
2021-10-31 13:00:05.000

CodePudding user response:

Perhaps the following is what you are after - the syntax will vary slightly depending on your particular RDBMS

select Convert(date, col) TheDate, Min(col) minDate, Max(col) maxDate
from t
group by Convert(date, col)

Edit

The following should be a suitable port for Snowflake

select To_date(col) TheDate, Min(col) minDate, Max(col) maxDate
from t
group by To_date(col)
  • Related