0

I am working in Yii framework. I am having Poll table with fields as- -pollId -pollQuestion -Isactive -publishDate -isPublish

when new poll is created,that date get inserted into publishDate field. e.g.2012-04-04 02:23:45 In this format entry get inserted. Now i want to check weather this publishDate is smaller than today's date or current date. i.e.publishDate should not be greater than current date. So how to check this in yii? Please help me

user1761116
  • 115
  • 1
  • 5
  • 14

1 Answers1

1

As per normal PHP. Assuming $model is the submitted form and you have assigned (after the form has been submitted) $model->attributes = $_POST['MyModel'] You can then use:

if ($model->publishDate < date('Y-m-d H:i:s')){
    // it is smaller
}

Another thing you could look at is using Yii's model validation. You could store the created date (which would be todays date) and then compare that to the publishDate in the form submit:

$model->created = date("Y-m-d H:i:s");
if ($model->validate){
    ...
}

And in your Poll model:

array('publishDate ','compare','created','operator'=>'<', 'message'=>'Publish Date must be smaller than the current date'),
Brett Gregson
  • 5,867
  • 3
  • 42
  • 60