简体   繁体   English

用php检查星期几

[英]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().

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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