Home > Net >  Check day of week with php
Check day of week with php

Time:03-05

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

CodePudding user response:

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 different param:

$day_name = date('l');
//$day_name = Monday. If lowercase is required, use strtolower().
  •  Tags:  
  • php
  • Related