Cactiveform Datefield Customization

Hi, I am using CActiveForm to create a form that has a dateField. I want to customize the format of the dateField, it is by default: Day/Month/Year. I also want to validate if the date is in the future. Any suggestions???


You can try this:

$pattern = 'dd/MM/yyyy';

$timestamp = strtotime($model->published_datetime);

if ($timestamp !== false)

	$model->published_datetime = Yii::app()->getDateFormatter()->format($pattern, $timestamp);


	$model->published_datetime =  '';

$this->widget('zii.widgets.jui.CJuiDatePicker', array(





		'minDate'=>'+1d',//day can choose >= tomorrow



in model

protected function beforeValidate()


	$timestamp = CDateTimeParser::parse($this->published_datetime, 'dd/MM/yyyy');

	if ($timestamp === false)

		$this->published_datetime = '';


		$this->published_datetime = date('Y-m-d', $timestamp);

	return parent::beforeValidate();


if you want to validate in model add rule validate date and use logic

public function rules()


        return array(




public function validateDate($attribute,$params){

//allow published_datetime empty

if (!empty($this->$attribute ))


	if (strtotime($this->$attribute) <= time())

		return false;


return true;