Mysql sort by date but ignore year

前端 未结 1 1768
旧巷少年郎
旧巷少年郎 2021-01-29 02:58

I have a table which has a Mysql DATE field type.

I am searching the entries and need to sort the entries soonest first within the next 30 days. BUT, some o

相关标签:
1条回答
  • 2021-01-29 03:31

    Figured it out:

    Answer

    select b.name, ue.event_title, ue.event_date,
    (DAYOFYEAR(ue.event_date) - DAYOFYEAR(CURDATE())) as days
    from brains b
    join user_events ue on b.user_id=ue.user_id
    where b.user_id=63 and 
    MOD(DAYOFYEAR(ue.event_date) - DAYOFYEAR(CURDATE()) + 365, 365) <= 30 
    order by days asc 
    
    0 讨论(0)
提交回复
热议问题