SELECT row by DATEPART()

后端 未结 4 500
耶瑟儿~
耶瑟儿~ 2020-12-03 21:24

I need to get rows from the database where the records are of one month. I tried this SELECT:

$result = mysql_query(\"SELECT * FROM my_table WHERE DATEPART(\         


        
4条回答
  •  失恋的感觉
    2020-12-03 21:42

    If your DATEPART is not working in MYSQL then you can use:

    SELECT * FROM MyTable WHERE MONTH(joinningDate)=MONTH(NOW())-1 and YEAR(joinningDate)=YEAR(NOW());
    

    It will return all records who have inserted in MyTable in last month.

提交回复
热议问题