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

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

    Current month:

    SELECT * FROM jokes WHERE YEAR(date) = YEAR(NOW()) AND MONTH(date)=MONTH(NOW());
    

    Current week:

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

    Current day:

    SELECT * FROM jokes WHERE YEAR(date) = YEAR(NOW()) AND MONTH(date) = MONTH(NOW()) AND DAY(date) = DAY(NOW());
    

    This will select only current month, really week and really only today :-)

提交回复
热议问题