close

要利用strtotime函數

計算日期的大小

以下為範例

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

$thisday = '2017-04-20';

if(strtotime($today)>strtotime($thisday))

echo '今天已過20號喔!';

else

echo '還沒到20號喔!';

也可以把上面變成function喔!

以下為function

function comparison_date($finaldate){

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

    if(strtotime($todate)>strtotime($finaldate))

        $message =  '今天已過'.$finaldate.'喔!';

    else

        $message =  '還沒到'.$finaldate.'號喔!';

    return $message;

}

arrow
arrow
    創作者介紹
    創作者 阿益 的頭像
    阿益

    程式設計

    阿益 發表在 痞客邦 留言(0) 人氣()