Select current months records mysql from timestamp column

前端 未结 10 2114
一整个雨季
一整个雨季 2020-12-05 15:31

I have a mysql DB that has a TIMESTAMP field titled date. How can I select all fields where the month is the current month?

Thanks in advance!

10条回答
  •  被撕碎了的回忆
    2020-12-05 16:00

    I think in MySQL here is the simplest method which i have tried and works well, you want to select rows where timestampfield is in this month.

    SELECT * FROM your_table 
    WHERE MONTH(timestampfield)=MONTH(CURRENT_DATE()) AND
    YEAR(timestampfield)=YEAR(CURRENT_DATE());
    

    the above will return all records that the timestampfield is this month in MySQL

提交回复
热议问题