简体   繁体   中英

Check day of week with php

I am trying to program a script that submits a form only on specific days of the week.

I have this code already.

date('w'); // gets day of week as number(0=sunday,1=monday...,6=sat)
    
// *note*: returns 0 through 6 but as string so to check if monday do this:
if(date('w') == 1){
    echo "its monday baby";
}

But I do not know if this is efficient enough. Please is there a better way around this

I think you have the best approach for this task. In case you want the name of the day, you can use the same fuction but a different param:

$day_name = date('l');
//$day_name = Monday. If lowercase is required, use strtolower().

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