开发者

date and time query in php

开发者 https://www.devze.com 2023-02-07 02:25 出处:网络
I\'m trying to select all the records that has the same month with the current month. $date=date(\'Y-m-d\');

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

精彩评论

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