How to Query Date and Time in MySQL

If you want to obtain data from any specific date, just put the date in the format ‘yyyy-mm-dd’. There are other date formats available like ‘mm-dd-yyyy’;

select * from sales where sale_day = '2021-08-11';

If you have a timestamp column and you want to obtain the sales done on each day at any specific period of time, for example between 11:00 am and 12:00 am, you can cast the timestamp to time and filter in a range of time.

select * from my_sales 
where cast(daytime as time) >= '11:00:00' 
  and cast(daytime as time) <= '12:00:00';

Or using the between operator:

select * from my_sales 
where cast(daytime as time) between '11:00:00' AND '12:00:00';

IN THIS PAGE