sql - Mysql sort by date but ignore year -
i have table has mysql date
field type.
i searching entries , need sort entries soonest first within next 30 days. but, of entries have years on them have expired recurring data.
for date find i'm using dayofyear
works great.
question is: can sort following least number of days until event, first?
select b.name, ue.event_title, ue.event_date brains b join user_events ue on b.user_id=ue.user_id b.user_id=63 , mod(dayofyear(ue.event_date) - dayofyear(curdate()) + 365, 365) <= 30 order event_date desc
order event_date desc
goes wrong because of year
figured out:
answer
select b.name, ue.event_title, ue.event_date, (dayofyear(ue.event_date) - dayofyear(curdate())) days brains b join user_events ue on b.user_id=ue.user_id b.user_id=63 , mod(dayofyear(ue.event_date) - dayofyear(curdate()) + 365, 365) <= 30 order days asc
Comments
Post a Comment