简体   繁体   中英

PHP - Get the current working day number of the current month

I found this code in a answer here on stack overflow which counts working days of a month.

function get_weekdays($m,$y) {
    $lastday = date("t",mktime(0,0,0,$m,1,$y));
    $weekdays=0;
    for($d=29;$d<=$lastday;$d++) {
        $wd = date("w",mktime(0,0,0,$m,$d,$y));
        if($wd > 0 && $wd < 6) $weekdays++;
    }
    return $weekdays+20;
}

How can I get the current day number if I run this function for current month? ( I don't have enough reputation to comment, so I posted a new question)

Current day (as in, today is 29 ) is just date("d") , day of the week is date("w") (3=Wednesday)

If you meant the working days for the current month, call that function with:

get_weekdays(date("m"), date("Y"));

To see what each format options means see the documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM