C5-8.3: how to handle datetime picker

Permalink
Following this:

https://documentation.concrete5.org/tutorials/how-to-use-the-date-ti...

I can't get the datetime picker to work. I tried the following:

form.php:
echo $app->make('helper/form/date_time')->date('valid_until', $valid_until);

controller.php save():
$args['valid_until'] = isset($args['valid_until']) ? $this->app->make('helper/form/date_time')->translate('valid_until') : date(t('d M Y'), time() + 86400);

db.xml:
<field name="valid_until" type="date" />

So having the above, I get a mysql error:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '' for column 'valid_until' at row 1 (0)

The controller translate doesn't look right. Should it have the following argument instead: 'translate($args['valid_until'])'? Otherwise what's 'valid_until' to it?

But if I change it to the above 'translate($args['valid_until'])', the mysql error goes away, but nothing gets saved in the DB, I get a 'NULL' value in the DB.

What am I doing wrong?

Thank you.

PS. According to the API, the following should show the date picker with options but it doesn't show it at all:
echo $app->make('helper/form/date_time')->date('valid_until', $valid_until, false);
echo $app->make('helper/form/date_time')->date('valid_until', $valid_until, false, array());

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
If I simply use this in save():
$args['valid_until'] = date(t('d M Y'), time() + 86400);

it throws an error:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '06 May 2018' for column 'valid_until' at row 1 (0)


And BTW,

1. The date in the form is always displayed as e.g. 05/06/2018 regardless of the time settings of the system. How can I force it to be displayed like, e.g. t('d M Y')?
2. The controller stores the entered date and time in another timezone in the DB. When I open the form, it translates the datetime automatically to the entered value. But when I use the value in view.php, it doesn't translate it and leaves it the same as in the DB. How can I display the right datetime in view.php, the same as was entered in the form?
linuxoid replied on at Permalink Reply
linuxoid
After a lot of playaround, I got this to work somehow:

form.php:
echo $app->make('helper/form/date_time')->datetime('valid_until', $valid_until, false);

controller.php save():
$args['valid_until'] = $this->app->make('helper/form/date_time')->translate('valid_until');

view.php:
echo t('Valid until: ') . date(t('d M Y H:i:s'), strtotime($valid_until));

db.xml:
<field name="valid_until" type="datetime" />

The problem however remains - if I enter 05/06/2018 01:00 AM in the form, 2018-05-05 14:00:00 is stored in the DB and the same is displayed in view as 05 May 2018 14:00:00.

So, how do I display in view the datetime exactly as was entered in the form?