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:
controller.php save():
db.xml:
So having the above, I get a mysql error:
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:
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():
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:
After a lot of playaround, I got this to work somehow:
form.php:
controller.php save():
view.php:
db.xml:
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?
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:
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?
it throws an error:
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?