Format Day In Week

I was requested to write a code in beforeValidate function which will block users from creating an account on Sunday , Monday and Tuesday.

I wrote the following code based on this documentation:

http://www.yiiframework.com/doc/api/1.1/CDateFormatter#formatDayInWeek-detail


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

$day=Yii::app()->dateFormatter->formatDayInWeek('EEEE', $today);

if($day='Saturday')

	Yii::app()->getController()->redirect('index.php?r=site/closed');

However it tell me that:

Any ideas why? (it accepted just format , but its not what I need)

Try this one.


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

$day = date('l', strtotime($today));

if($day=='Saturday')

    Yii::app()->getController()->redirect('index.php?r=site/closed');

Seems like it works , but only when I added another =


if($day=='Saturday')

Whats the 1 stands for?

Thank you very much Jbal !

Cheers ,

Mark.

Oh I forgot to add another ‘=’.

it’s not 1, it’s ‘l’. It’s the formatting options for date() function.


$dayOfWeek = date('w');

select $dayOfWeek {

   case 0: //Sunday

   case 1: //Monday

   case 2: //Tuesday

      //Oh No you can't <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />

      Yii::app()->getController()->redirect('/site/closed');

      break;

   default:

      // Ok you can do it.

      Yii::app()->getController()->redirect('/site/open');

      break;

}

Hey read about the PHP Operators ‘=’ is an assignment operator, while ‘==’ is a comparison operator.

I hope that makes sense!