Select records from today, this week, this month php mysql

前端 未结 11 871
粉色の甜心
粉色の甜心 2020-12-12 10:50

I imagine this is pretty simple, but can\'t figure it out. I\'m trying to make a few pages - one which will contain results selected from my mysql db\'s table for today, thi

11条回答
  •  忘掉有多难
    2020-12-12 11:01

    To get last week's data in MySQL. This works for me even across the year boundries.

    select * from orders_order where YEARWEEK(my_date_field)= YEARWEEK(DATE_SUB(CURRENT_DATE(), INTERVAL 1 WEEK));
    

    To get current week's data

    select * from orders_order where YEARWEEK(date_sold)= YEARWEEK(CURRENT_DATE());
    

提交回复
热议问题