DateTime field Issues

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

DateTime field Issues

Post by wilmira » 2018-06-06 21:10

Hello everybody,

I have tried, without success, to show dates in UK format, however nothing I try works. I am using Appgini Version 5.62.

I have set my preference as UK format in my app, and it works fine with date fields, but not with DateTime fields, these fields keep presenting the US date and time format. Data format for each field is chosen as Default

I have tried setting my preferences as US format and choosing the Data Format for each field as UK format, This causes an error on some fields controlled by a script in a hook (it writes 0000-00-00 00:00:00, instead of the actual date time).

The script that writes on the DateTime fields is in the hooks/orden.php file and it is in the before_insert and before_update functions:

function orden_before_insert(&$data, $memberInfo, &$args){

$preporini = $data['prep_orden'];
$servorini = $data['serv_orden'];
$tim_stamp=date('Y-m-d G:i:s');
$estorden = $data['estado_orden'];
if($estorden == 'Preparada' && !$preporini){
$data['prep_orden'] = $tim_stamp;
}else if ($estorden == 'Servida' && !$servorini){
$data['serv_orden'] = $tim_stamp;
}else {
$data['serv_orden'] = $servorini;
$data['prep_orden'] = $preporini;
}

return TRUE;
}

Something else, the variable: $tim_stamp=date('Y-m-d G:i:s'); only works when I use this format, if I use this one: $tim_stamp=date('d/m/Y H:i:s'); it won´t work, the output is always 0000-00-00 00:00:00.

Can anybody know why is this happening.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: DateTime field Issues

Post by pbottcher » 2018-06-07 13:09

Hi,

I think this is a feature.

You can change the datetime format through the "data format" tab for the field. This should be reflected in the TV. In the DV you still get the default setting as this is what is used to update the database. And the format for the database is xxxx-xx-xx xx:xx:xx.

This is also the reason for you to put the date as xxxx-xx-xx xx:xx:xx (= date('Y-m-d G:i:s') ) into the $data variable. If you put non-valid date format in there, it will cause 0000-00-00 00:00:00 to be written in the database.

regards
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

Re: DateTime field Issues

Post by wilmira » 2018-06-07 21:10

Thank you very much pböttcher for your help.

That was exactly the issue, the format type of the fields.

To solve it, I changed to the US format in Preferences like this: Year-month-day, and the separator as hyphen (-).

However there were always issues with the data shown on the TV. I have a field as Time, another as Date and some others as DateTime. All of them with the tab format chosen as UK Short Date/Time, however, the fields with Date format, did not changed to UK Short Date/Time, so I had to create a new format just for that Date field (UK Short Date (example: 28/3/2008); DATE_FORMAT(%%FIELD%%, '%e/%c/%Y')).

Is this a bug?

Thanks again for your help.

Post Reply