calendar form field cannot be saved in db without time portion of date

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
greenhela
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Dec 06, 2017 5:30 pm

calendar form field cannot be saved in db without time portion of date

Post by greenhela » Wed Oct 03, 2018 5:41 pm

Hi there,

my problem is still the same (I have posted before).. I found a solution but it's not nice and I would love to get an insight why this doesn't work as one would expect.
So, here's the setup. I have a component, where in the backend record editing form, there's a date picker. This date is a varchar field in the database and I would like to leave it so before I break a 1000 more things.. The proper format this date initially gets saved in in the frontend is YYYY-mm-dd. In my administrator/components/mycomponent/models/forms/tralala.xml the field is type calendar. I set the format attribute, the showtime attribute, tried even the translateformat attribute, to all combinations but joomla ALWAYS saves the date with the trailing time portion which is always 00:00:00. The joomla docs about the calendar form field says:
note that the format string must include time fields for the time to be recorded
Well it certainly doesn't record the time properly but still puts that time portion in there.This for some reason messes up the dates as soon as i set the server timezone to something else than UTC.
Why this behavior? Is there any way of changing it without overriding the whole save procedure in mycomponent/controllers/tralala.php or what i did (coz i don't want to mess with the original save function and don't even know where to look for it to be able to copy it to my override and change only the part i need to), which is call

Code: Select all

parent::save();
, and then just update that record again to set that varchar date field to what i need?

Thanks...

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30938
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: calendar form field cannot be saved in db without time portion of date

Post by Per Yngve Berg » Wed Oct 03, 2018 6:14 pm

The column should been of type "Date", not "varchar".

https://dev.mysql.com/doc/refman/5.7/en ... types.html

greenhela
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Dec 06, 2017 5:30 pm

Re: calendar form field cannot be saved in db without time portion of date

Post by greenhela » Mon Oct 08, 2018 10:29 am

hey there, thanks, i know that but i did not write the component and i'm afraid if i change that it might affect other parts of it that i'm gonna have to find and adjust..

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2909
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: calendar form field cannot be saved in db without time portion of date

Post by SharkyKZ » Mon Oct 08, 2018 12:54 pm

If you can't change the DB column, set filter attribute of the field to string.

greenhela
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Dec 06, 2017 5:30 pm

Re: calendar form field cannot be saved in db without time portion of date

Post by greenhela » Sat Oct 27, 2018 2:45 pm

Hey there, you mean in the joomla xml? According to documentation a calendar form field type's filter can only be set to 'server_utc' or 'user_utc..'


Locked

Return to “Joomla! 3.x Coding”