Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL search between two days without datetime

Trying to search in a database a date range. Problem is, I cannot use the datetime column type in my database. To compensate, date's are displayed as three columns. a Month column, a Day column, and a Year column. Here is my SQL query:

SELECT COUNT(*) 
  FROM `import` 
 WHERE `call_day` BETWEEN 29 AND 15 
   AND `call_month` BETWEEN 9 AND 10 
   AND `call_year` BETWEEN 2013 AND 2013

You can see where I run into trouble. call_day needs to search between the 29th day and the 15th day. This won't work because 15 is smaller than 29, but I need it to work because the month is in the future :)

Any thoughts/solutions? No I cannot change the database in any way. Read only.

like image 424
Jer_TX Avatar asked Jan 13 '23 03:01

Jer_TX


1 Answers

Concat the values like yyyymmdd and then you can compare them like strings.

like image 89
Jonysuise Avatar answered Jan 22 '23 13:01

Jonysuise