⚠ 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

date time - Format



Jerfeson Guerreiro
  • profile picture
  • Member

Posted 23 February 2014 - 02:00 AM

 
Hello guys good night - I am Brazilian, again with codeigniter and grocery cryd.



I have a question, I created a date field, which will automatically updated
. it has the following structure.

 

config/grocery_crud.php

	$config['grocery_crud_default_language']	= 'pt-pt.portuguese';

	// There are only three choices: "uk-date" (dd/mm/yyyy), "us-date" (mm/dd/yyyy) or "sql-date" (yyyy-mm-dd)
	$config['grocery_crud_date_format']			= 'uk-date';

controllers/seg

 

 $crud->set_table('seguradoras');
        $crud->columns('dataInscricao');
        $crud->fields('dataInscricao');

        $crud->change_field_type('dataInscricao','hidden');

        $crud->callback_before_insert(array($this,'callback_insert'));
        $crud->callback_before_update(array($this,'callback_update'));

function callback_insert($post_array)
    {
        $post_array['dataInscricao'] = date('d-m-Y H:i:s');
        $post_array['dataInscricao'] = date('d-m-Y H:i:s');
        return $post_array;
    }

    function callback_update($post_array)
    {
        $post_array['dataInscricao'] = date('d-m-Y H:i:s');
        return $post_array;
    }

However he accepts not registering the date on bench with d-m-Y format, only with Y-m-d.

 

Does anyone know the solution to this

he is just not loading the data adds

 
Is thus showing

 

 

2014-02-22 23:12:13

 

But the idea is thus shown that

 

22-02-2014 23:12:13

 

 

 

 


Amit Shah
  • profile picture
  • Member

Posted 24 February 2014 - 16:53 PM

Hi there

 

1 - mysql accepts the format - Y-m-d ... and not d-m-Y

2 - as for display of the date - u can make a callback_column('thedatefield', array($this, 'formatMySqlDate'))

 

create a new function in controller formatMySqlDate  -  here - do the formatting to the date and return it back for display...

 

Happy GCing:)