How to Validate two dates
- Single Page
Posted 01 May 2012 - 02:33 AM
[img]http://content.screencast.com/users/Lucasturilli/folders/Jing/media/63da5893-1e55-48d1-9194-10dc9055c05f/2012-04-30_2130.png[/img]
Posted 17 May 2012 - 15:32 PM
Posted 23 May 2012 - 22:04 PM
Posted 24 May 2012 - 18:07 PM
$crud->render();
enter:
$crud->set_rules('fecha2','Fecha de Finalización','callback_check_dates[fecha1]');
Then add this function to your controller:
public function check_dates($fecha2, $fecha1)
{
if ($fecha2 >= $fecha1)
{
return TRUE;
}
else
{
$this->form_validation->set_message('check_dates', "La fecha de inicio no puede ser posterior a la fecha de finalización.");
return FALSE;
}
}
(Sorry about all the edits, the interface hates me.)
Posted 10 June 2012 - 06:52 AM
What I'm doing wrong?
...
$this->grocery_crud->set_rules('periodto','Period to','callback_check_dates["periodfrom"]');
$output = $this->grocery_crud->render();
...
public function check_dates($datet2,$date1)
{
if ($datet2 >= $date1)
{
return TRUE;
}
else
{
$this->form_validation->set_message('check_dates', $datet2.' date 2 is smaller then '.$date1.' date 1.');
return FALSE;
}
}
Date field $date1 appiers as word "periodfrom" not as value.
How to feed second value correctly to the callback function?
Posted 21 June 2012 - 22:02 PM
La fecha de inicio no puede ser posterior a la fecha de finalización.etapa_fecha_inicio07/06/2012
Posted 23 June 2012 - 02:04 AM
You gotta make sure the data is in this format: YYYY-mm-dd , like 2012-06-22.
Try read more about explode and join on the internet.
Try this:
public function check_dates($fecha2, $fecha1)
{
$partes = explode('/', $this->input->post('fecha1'));
$fecha1 = join('-', $partes);
$partes2 = explode('/', $this->input->post('fecha2'));
$fecha2 = join('-', $partes2);
if ($fecha2 >= $fecha1)
{
return TRUE;
}
else
{
$this->form_validation->set_message('check_dates', "La fecha de inicio no puede ser posterior a la fecha de finalización.");
return FALSE;
}
}
Posted 15 August 2014 - 21:42 PM
Thanks alot. This worked for me :)
Posted 01 September 2017 - 05:17 AM
This works only when we enter the dates of the same month, If I enter 1/08/2017 and 28/07/2017 , It should show an error message(end date should be greater than start date) but it is actually inserting the dates in to the database , Can anyone help me with this..?
Posted 01 September 2017 - 06:08 AM
I found it , This will work for all cases,
$crud->set_rules('end_date', 'end_date', 'trim|callback_check_dates['.$this->input->post('start_date') .']');
// Callback function