开发者

date and time query in php

I'm trying to select all the records that has the same month with the current month.

 $date=date('Y-m-d');

    $month=substr($date,5,2);


    $res=mysql_query("SELECT DATE FROM reports");
    while($row=mysql_fetch_assoc($res)){

    $months开发者_运维百科=substr($row['DATE'],5,2);

}

How can I do it?


You could sql let handle that for you like this

$query = "SELECT DATE FROM reports WHERE MONTH(DATE) = ".date("m");

in case you want only everything of that month this year then the query would look like this:

$query = "SELECT DATE FROM reports WHERE YEAR(DATE) = ".date("Y")." MONTH(DATE) = ".date("m");


Why not

$query = 'SELECT DATE FROM reports WHERE MONTH(DATE) = MONTH(CURDATE())';

?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜