⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Set default date in a BD record



MiguelR
  • profile picture
  • Member

Posted 31 March 2017 - 14:09 PM

good morning!! I'm new. When selecting the option to add a record, the default date appears but at the time of saving it is not saved and in the main table does not appear, attached images of the problem

 

 

 

public function asignaciones_Equipos()

{

$crud = new grocery_CRUD();

            $crud->set_theme('flexigrid');

$crud->set_table('asignaciones_equipos');

$crud->columns('idEquipo','idEmpleado','idSector','fechaAsignacion');

$crud->set_subject('asignaciones_Equipos');

$crud->set_relation('idEmpleado','empleado','{apellido} {nombre}');

$crud ->set_relation('idSector','sector','{idSucursal} - {Sector}');

            $crud ->set_relation('idEquipo','equipos','{idEquipo} - {descripcion}');

            $crud->display_as('idSector','Cod_Suc - Sector')

                 ->display_as('idEmpleado','Empleado')

                 ->display_as('idEquipo','Nº Equipo - Descripcion');

 

                 $crud->set_rules('idEquipo','Equipo','callback_equipo_check');

                 $crud->callback_add_field('fechaAsignacion',array($this,'_add_default_date_value'));

$output = $crud->render();

 

$this->_example_output($output);

}

public function _add_default_date_value(){

$value = date('d/m/y');

        $return =$value;

        return $return;

}

Set default date in a BD record


xheradon
  • profile picture
  • Member

Posted 03 April 2017 - 06:47 AM

And what about setting default date on server side instead of client side? It's easier I think.


MiguelR
  • profile picture
  • Member

Posted 04 April 2017 - 02:25 AM

And what about setting default date on server side instead of client side? It's easier I think.

I am very young in this subject and it costs me a lot, you would not have some example to solve this problem or some way to do it


xheradon
  • profile picture
  • Member

Posted 04 April 2017 - 06:37 AM

Go to your phpmyadmin (or whatever you are using to manage your database) and set your column 'fechaAsignacion' DEFAULT CURRENT_TIMESTAMP so whenever you set a new record 'fechaAsignacion' will have the current date and time automatically.

 

ALTER TABLE table MODIFY fechaAsignacion NOT NULL DEFAULT CURRENT_TIMESTAMP