how to query date in sql server 1

how to query date in sql server

select  *
from events
where event_date between '2020-01-01' and '2020-01-31';

-- can include time by specifying in YYYY-MM-DD hh:mm:ss format:
select  *
from events
where event_date between '2020-01-01 12:00:00' and '2020-01-01 23:30:00';

Here is what the above code is Doing:
1. We’re selecting all the columns from the events table.
2. We’re filtering the results to only include rows where the event_date is between January 1st, 2020 and January 31st, 2020.
3. We’re filtering the results to only include rows where the event_date is between January 1st, 2020 at 12:00:00 and January 1st, 2020 at 23:30:00.

Similar Posts