Database time field

Permalink
Is it possible to create a field containing only a time in my db?

I now have:
<field name="time" type="T"></field>

But this gives me a datetime field in my database.

 
codingpenguins replied on at Permalink Reply
You did not display the code right. Remember to use the [code] tags. Also in mysql there is a "time" type field. This will not display a date.
rklomp replied on at Permalink Reply
I did not see that it had disappeared.
<field name="tijd1" type="T"></field>


I know MySQL has a time field, but how do I create one in my db.xml file?
Mainio replied on at Permalink Reply
Mainio
codingpenguins replied on at Permalink Reply
This seems to not answer the question. Klompie was asking for a time type. I seen the information you presented and it does not talk about this. Klompie issue is that it does not just work for time.
Mainio replied on at Permalink Reply
Mainio
I think it answers the question since IMO it shows pretty clearly that defining the MySQL TIME field type with AdoDB Schema is not currently possible.

This is what it reads in the adodb MySQL dialect:
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP': return 'T';


And when returned to the MySQL type this is what the same class states in adodb:
case 'T': return 'DATETIME';


So, also that shows IMO that the TIME type is not possible to define with adodb. I think the reason for this is that this might not be defined in all the dialects that adodb supports.

Also, the link below shows how to create custom queries with the adodb schema language, so that might also help to solve the problem.



Antti / Mainio
codingpenguins replied on at Permalink Reply
Yes I agree. We both came to the same conclusion. I am interested why no one using adodb have came across this issue. I believe it would be possible, I have made several changes to adodb because of lack of functionality. I would believe it would be as easy as adding a new variable to just represent time and just return by 'TIME' type when this variable is called.
Mainio replied on at Permalink Reply
Mainio
I think hacking the core or 3rdparty libraries is rarely the way to go. I don't recall a time I would've needed the TIME field last time even in projects without c5.

Also, there are multiple workarounds available so it shouldn't be that much of a problem.

Only thing that comes to my mind at this moment where you might need the TIME field is in calendar for repeating events (e.g. every Monday at 8 A.M.). Then again, in that case you would probably already have a data structure that stores the date+time for the event so in that case you could e.g. set the time for the first occurrence of that event and for repeating events parse the time for that event when it appeared the first time.


Antti
mkly replied on at Permalink Reply
mkly
AFAIK this is because of cross compatibility.
codingpenguins replied on at Permalink Best Answer Reply
You can read the first one that Mainio sent you (http://www.concrete5.org/documentation/how-tos/developers/creating-and-working-with-db-xml-files/), but there is NOT a time way to do this. All "T" will convert to Date-time. You have two options.

1) Create using "T" and just strip the date everytime.
2) Create your own custom "T" to add Time. The needed logic will go in /concrete/libraries/3rdparty/adodb/datadict/datadict-mysql.inc.php. If you what to do this I will be glad to help, but this is an internal library file.
Mainio replied on at Permalink Reply
Mainio
Yes, you have to create some kind of workaround for it. I'd suggest e.g. basic integer field for stating seconds from the beginning of the day.

There might be even better workaround but I think try to use a field type with which you need to store as little "useless" information as possible. So e.g. storing times always with some year might not be optimal...
rklomp replied on at Permalink Reply
Thanks! your section option did it :).

But now i have a changed core file.. So when updating the core system this file will be overwritten. Is there a way to prevent this?
codingpenguins replied on at Permalink Reply
You can try the overriding technique.http://www.concrete5.org/documentation/how-tos/developers/change-th... kinda explains it.

So if you should add this file to /libraries/3rdparty/adodb/datadict/datadict/mysql.inc.php - this should override the file in /concrete/libraries/3rdparty/adodb/datadict/datadict/mysql.inc.php

This usually works for me, I forget when it does not work.

- I agree with Mainio (Antti) above that messing with the core is usually not the way to go. So you just might want to rethink exactly how everything is set up.