Yii Framework Forum: [ASK] Model Rules (date/tanggal) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[ASK] Model Rules (date/tanggal) Rate Topic: -----

#1 User is offline   kfahmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 19-March 12

Posted 08 May 2012 - 11:39 PM

ada yang tau gak cara validasi tanggal kalo format ane tau

array('date_from, date_to', 'date', 'format'=>'yyyy-mm-dd', 'allowEmpty' => true, 'message'=>'date(y-m-d) are mandatory',),


yang ane butuh date_from lebih kecil(<) dari date_to,, gimana ya cara nya?
0

#2 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 09 May 2012 - 04:46 AM

coba kaya gini deh..

array('date_from, date_to', 'validDate' )


public function validDate($attribute, $params)
{
  if($this->date_from < $this->date_to)
  {
     $this->addError('date_to',' '.$this->date_to.' harus lebih besar dari '.$this->date_from);
     //return false;
  }
}



belom di test sih..
tapi semoga aja bisa..
hahaha...
ditaro di model yang bersangkutan ya..
belajar itu mudah..
0

#3 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 09 May 2012 - 04:54 AM

ato ga kaya gini...
array('date_from, date_to', 'validDate' )


public function validDate($attribute, $params)
{
  $date_1 = $this->date_from; //buat tanggal format yyyy-mm-dd
  $date_2 = $this->date_to;  //buat tanggal format yyyy-mm-dd

  list($year, $month, $day) = explode('-', date_1);
  $new_date_1 = sprintf('%04d%02d%02d', $year, $month, $day);
  list($year, $month, $day) = explode('-', date_2);
  $new_date_2 = sprintf('%04d%02d%02d', $year, $month, $day);
    if ($date_2 < $date_1) {
     $this->addError('date_to',' '.$this->date_to.' harus lebih besar dari '.$this->date_from);
    }
}

tinggal di coba-coba aja...
belajar itu mudah..
0

#4 User is offline   kfahmi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 19-March 12

Posted 09 May 2012 - 10:31 PM

View Postteguh11, on 09 May 2012 - 04:54 AM, said:

ato ga kaya gini...
array('date_from, date_to', 'validDate' )


public function validDate($attribute, $params)
{
  $date_1 = $this->date_from; //buat tanggal format yyyy-mm-dd
  $date_2 = $this->date_to;  //buat tanggal format yyyy-mm-dd

  list($year, $month, $day) = explode('-', date_1);
  $new_date_1 = sprintf('%04d%02d%02d', $year, $month, $day);
  list($year, $month, $day) = explode('-', date_2);
  $new_date_2 = sprintf('%04d%02d%02d', $year, $month, $day);
    if ($date_2 < $date_1) {
     $this->addError('date_to',' '.$this->date_to.' harus lebih besar dari '.$this->date_from);
    }
}

tinggal di coba-coba aja...



guh gue dapet yang simple nih, udah dibuatin sm YII tinggal dipake aja hehe

 array('date_from','compare','compareAttribute'=>'date_to','operator'=>'<', 'message'=>'Date_from must be less than Date_To'),			


Yii mantap
0

#5 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 09 May 2012 - 11:21 PM

View Postkfahmi, on 09 May 2012 - 10:31 PM, said:

guh gue dapet yang simple nih, udah dibuatin sm YII tinggal dipake aja hehe

 array('date_from','compare','compareAttribute'=>'date_to','operator'=>'<', 'message'=>'Date_from must be less than Date_To'),			


Yii mantap


wah mantap dah...
yang susah jadi gampang..
Yes,It Is...
belajar itu mudah..
0

#6 User is offline   giantdut 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 24-April 12
  • Location:Jakarta, Indonesia

Posted 22 May 2012 - 10:16 AM

Hallo,

Kalo mau read data bulan ini gimana yah?

	public function monthly($month,$limit)
	{
	    $this->getDbCriteria()->mergeWith(array(
			'condition' => 'tanggal=:tanggal',
			'params' => array(':tanggal' => $month),
	        'limit'=>$limit,
	    ));
	    return $this;
	}	 


kalo gini month nya gimana yah?
Try to explore my intellectual capital
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users