How to filter results by time?

Hello,
here is my query:

 SELECT ticket, o_time, type, size, item, o_price, s_l, t_p, c_time, c_price, profit
 			   FROM data 
 			    ORDER BY c_time

Here is an example of c_time time stamp:
2018-04-17 16:58:25

I want to filter results by time.
Onec according to dates e.g. between April 1th 2017 and September 4th 2019 or from March 5th onards

I tried

SELECT ticket, o_time, type, size, item, o_price, s_l, t_p, c_time, c_price, profit   FROM data  WHERE DATE_FORMAT(c_time, '%Y-%m-%D') >= '2018-03-05' 
 ORDER BY c_time

The WHERE DATE_FORMAT(c_time, ‘%Y-%m-%D’) >= ‘2018-01-01’ was ignores. I got results as if this dae filtering condition doesn’t exist

I also tried filterin results by day of week adding

WHERE DATE_FORMAT(c_time, '%w') = 4

nothing happened. I got results as if the where condition doesn’t exist
What do I do wrong?

date_format returns a string, not a date, doesn’t it?

SELECT ticket
     , o_time
     , type
     , size     
     , item
     , o_price
     , s_l
     , t_p
     , c_time
     , c_price
     , profit 
  FROM data  
 WHERE c_time >= '2018-03-05' 
 ORDER BY c_time

Thanks for the quick heplin answer.
How do I filter results by weekdays e.g. c_time is on wednesday or c_time weekday = 3?

  1. How do I filter results between 14:00 and 19 :00 (huors) ?

How do I filter results by weekdays

WHERE DAY_OF_WEEK(c_time) = 4

Sunday = 1, Saturday = 7

  1. How do I filter results between 14:00 and 19 :00 (huors) ?
WHERE HOUR(c_time) BETWEEN 14 AND 19

NOTE: Those should work, but since I don’t do mySQL regularly, test them. But simple searches found these…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.