Jump to content

RenderForm, mysql and datetime fields conversion


Recommended Posts

Hi there!
I'm trying to figure out how to work with dates and datetimes with the renderForm and objectModel
for the helperForm i've
$fields_form = array( 

'legend' => array(
'title' =>$this->l('Abrir Caja'), 

// Fields
'input' => array(
'id_caja' => array('type' => 'hidden', 'name' => 'id_caja' ), 'date_caja'=>array( 'type' => 'datetime', 'label' => $this->l('fecha:'), 'name' => 'date_caja', 'id' => 'date_caja',  'lang' => false, 'required' => true, 'size'=>10,),


At this point i've 2 questions:
1 - How should i populate the datefield with the current date and time according to prestashop timezone and language settings? I've tried this:
'date_caja' => Tools::displayDate(date("Y-m-d H:i:s"), $default_lang, true)
so the date shows in EU format, i,e,  29/08/2015 14:34:12. but i think there must a much simplier way of doing this. 
2- using the above method, i dont know how to use Prestashop built functions to convert that date to a mysql datetime before saving the object to database. Now i'm using:
$tmp = str_replace( "/", "-", Tools::getValue( 'date_caja' ) );
$_newobj->date_caja = date("Y-m-d H:i:s",strtotime( $tmp ));
I think i'm little lost here. Any help would be much appreciated.
Edited by acuarelweb (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...