CjuiDatePicker


i haved tried use CJuiDatePicker but not change this value always 1970/01/01 07:00:01 AM


this my code


<div class="row">

<?php echo $form->labelEx($model,'time'); ?>

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

'model'=>$model,

'attribute'=>'time',

'options'=>array(

//'showAnim'=>'slideDown', // 'show' (the default), 'slideDown', 'fadeIn', 'fold'

'showOn'=>'button', // 'focus', 'button', 'both'

'buttonImage'=>Yii::app()->request->baseUrl.'/images/calendar.png',

'buttonImageOnly'=>true,

'htmlOptions'=>array('readonly'=>"readonly"),

'changeMonth'=>true,

'changeYear'=>true,

'mode'=>'datetime',

'dateFormat'=>'dd/mm/yy',

'htmlOptions'=>array(

'size'=>43,

'value'=>(!empty($model->time))?(is_numeric($model->time))?date('d/m/Y',$model->time):$model->time:date('d/m/Y')),


)));?>

<?php echo $form->error($model,'time'); ?>

</div>


can you help me? 

$model->time is probably 0 (matches the numeric check and results in the date you posted)

yes i think that. my $model->time is 0. but how can i get value from CJuidatePicker ? it is the problem

i know why the result only 1970/01/01 it is system time (http://en.wikipedia.org/wiki/System_time ) but i cann’t change it to really time. (T.T) can you help me?

the code you posted is correct, the problem is before you save to the datebase, when you convert from string to integer

try


list($d,$m,$y)=explode("/",$model->time);

$model->time=mktime(0,0,0,$m,$d,$y);

i tried to use it but this the result




        mktime() expects parameter 5 to be long, string given 



emmmm have mistake in my code ?




 public function beforeSave()

        {

			if(parent::beforeSave())

			{

				if($this->isNewRecord)

				{

					$this->timeCreate=$this->timeCreate=time();

                    $this->newsdtime=date('Y-m-d', strtotime($this->newsdtime));

					list($d,$m,$y)=explode("/",$model->newsdtime);

					$model->newsdtime=mktime(0,0,0,$m,$d,$y);

					return TRUE;

              //      return parent::beforeSave();

				}

				else

						$this->timeCreate=time();

					//return true;

			}

			//else

       } //End beforeSave()    




the result it’s enter in database. but the result it always use year 1970 but the minutes is change … date year and month not change. i think it is about time system what are you think?

gustavo i know why my code error . but i always can convert unix_time_stamp (197001/01 …) in really time. i use your code is work but canc’t convert it to really time …

as you use Y/m/d


list($year,$month,$day)=explode("/",$model->time);

$model->time=mktime(0,0,0,$month,$day,$year);

$this->time=date(‘Y/m/d’,($this->time));

list($year,$month,$day)=explode("/",$this->time);

$model->time=mktime(0,0,0,$month,$day,$year);

the result:




	1970/01/01 07:32:50 AM



the result change but only this 07:32:50 not 1970/01/01. T.T

I just tested here and works as expected


$time=date('Y/m/d',time());

echo $time."<br />";

list($year,$month,$day)=explode("/",$time);

$time=mktime(0,0,0,$month,$day,$year);

echo $time."<br />";

echo date('Y/m/d',$time);

die;

output




2011/07/30

1311984000

2011/07/30



you must define that time is a date in your model’s rules

thanks gustavo. it is work very well. i have mistake. in fact the atribut can save to database it is make me assume that it is n’t work. i must repaire my controller and model why cann’t save to database. what are you think ???

Gustavo i am happy. i can finished the problem.

ehmmm… it cause you thanks.

Ok i tell the story. if i use $time=mktime(0,0,0,$month,$day,$year); it is cann’t save in database so i make new attribute to temporary ($_time). and the really $time i change it’s type to integer. and $time=$_time and it is work. thank you want to help me.

code i am edit

[EDIT]




public function beforeSave()

	 {

		

				    $this->timeCreate=$this->timeCreate=time();

			  	    $temp=date('Y/m/d',strtotime($this->_time));

				    list($year,$month,$day)=explode("/",$temp);

				    $temp=mktime(0,0,0,$month,$day,$year);

				    $this->time=$this->time=$temp;

					

			return parent::beforeSave();

	}



it is work. thanks Gustavo. :D