mysql - Select records between two columns with date and ignoring Year from date column -
mytable events looks this:
id | from_date | to_date 1 | 2014-10-01 | 2015-02-20 2 | 2014-08-25 | 2015-04-01
from_date , to_date date columns year isn't of import becouse events every year same time. illustration between 10-01 02-20 every year.
i want select events in today 10-22
i trying using dayofyear without success.
select * mytable dayofyear('2014-10-22') between dayofyear(`from_date`) , dayofyear(`to_date`)
between date_format(from_date,'%m%d') doesn't work
any help great!
you need reverse status when to_date
in next year after from_date
.
select * mytable (year(from_date) = year(to_date) , dayofyear('2014-10-22') between dayofyear(from_date) , dayofyear(to_date)) or (year(from_date) != year(to_date) , dayofyear('2014-10-22') not between dayofyear(to_date) , dayofyear(from_date))
demo
mysql date datetime datediff
No comments:
Post a Comment