mysqlsqldatetimetimestr-to-date

Query for daily before 11am with MySQL


I have a datetime field and want to get all entries before 11am. It is for an online store where you can order until 11:00am and it will be shipped the same day.

SELECT * 
FROM Tablename 
WHERE (order.date_added < STR_TO_DATE(YEAR(), MONTH(), DAY()'%Y %d,%M'), '11:00:00')

Unfortunately, I do not know how to assemble this statement.


Solution

  • If you want orders before 11:00 a.m. today, you can use:

    where o.date_added >= curdate() and
          time(o.date_added) < '11:00:00'