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

前端 未结 11 846
粉色の甜心
粉色の甜心 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:12

    Try using date and time functions (MONTH(), YEAR(), DAY(), MySQL Manual)

    This week:

    SELECT * FROM jokes WHERE WEEKOFYEAR(date)=WEEKOFYEAR(NOW());
    

    Last week:

    SELECT * FROM jokes WHERE WEEKOFYEAR(date)=WEEKOFYEAR(NOW())-1;
    

提交回复
热议问题