Convert timestamp to readable date/time
My db have store datetime in (int, 11), now i want to view it when form load/edit to readable datetime.
I used:
$read_datetime = date('d-m-Y',$fields['datetime']);
$fields['datetime'] = array('value' => $read_datetime);
When form edit load, It's still display datetime like '124234772'. So that, I used other way to overwrite form.
In custom_fields.php:
$fields['read_datetime'] = array(
'class' => array(FUEL_FOLDER => 'Fuel_custom_fields'),
'function' => 'real_datetime',
'filepath' => '',
);
In Fuel_custom_fields.php:
public function real_datetime($params)
{
$form_builder =& $params['instance'];
$params['value'] = date('d-m-Y', $value);
$params['type'] = 'text';
return $this->$params;
}
In my model:
function form_fields($values = array(), $related = array())
{
$option_date = $fields['start_time'];
$fields['start_time'] = array('order' => 3, 'type' => 'read_datetime', 'values' => $option_date);
}
But It's not working. Just display datetimepicker.
How could I edit datetime in form view edit to view datetime like mm/dd/yy : hh:mm:ii ?
Thanks
Comments
... function my_find_one_array($where) { $data = parent::find_one_array($where); foreach($data as $key => $val) { $data[$key]['start_time'] = date('d-m-Y', $val); } return $data; } ...
Then in your fuel/application/config/MY_fuel_modules.php file, add the edit_method parameter:
.... $config['modules']['my_module'] = array( ... 'edit_method' => 'my_find_one_array', ... ); ....
The second method you could also try is adding a 'pre_process' parameter:
public function real_datetime($params) { $form_builder =& $params['instance']; $func_str = ' return date('d-m-Y', $value); '; $func = create_function('$value', $func_str); $form_builder->set_pre_process($params['key'], $func); return $this->create_datetime($params); }
I'm truly thanks. I'm new at FUEL CMS. 2 way of ur suggest i have try but not success. Would you mind to give me an example. Thanks
A Database Error Occurred
Error Number: 1054
Unknown column '12906' in 'where clause'
SELECT `users`.* FROM (`users`) WHERE `12906` IS NULL LIMIT 1
... function my_find_one_array($id) { $where['id'] = $id; $data = parent::find_one_array($where); foreach($data as $key => $val) { $data[$key]['start_time'] = date('d-m-Y', $val); } return $data; } ...