5
I am in doubt which type I should use to work with hours on my system. I should use DateTime
, Time
or TimeStamp
. I would like the hours to be saved in this format:
HH:MM
5
I am in doubt which type I should use to work with hours on my system. I should use DateTime
, Time
or TimeStamp
. I would like the hours to be saved in this format:
HH:MM
11
There is one specific type for this which is the TIME
. This type has the seconds and fraction of them too (keep them zeroed if you don’t need them), but in general it won’t be a problem.
But it is not always necessary to use it. There are some situations that a type VARCHAR
may be enough. Of course it is more limited, does not have the best semantics, but depends on the use. If you really want to avoid seconds, it would be this way. You will have to handle the data manually.
On the other hand it is possible that this type is not sufficient for what you want and you need to use another type where you have more control, even if it is at a cost of less facilities. In some cases it may be the VARCHAR
same. In others it may be interesting to use the DATETIME
or TIMESTAMP
, even if they have irrelevant information.
Just seeing the exact situation to decide which is best. But I’ll go on the native types first. If it is the case to sin by excess would be more advantageous in most cases.
Browser other questions tagged mysql sql database typing time
You are not signed in. Login or sign up in order to post.
I understand, in my case I’m making a schedule. Where I have the start time and the end time of an appointment. And in the future there should be a comparison so that I can not add any compromise if there is already one in the registered time. In that case it would be better to use which form?
– DiegoAugusto
I would take the
TIME
same. Keeping seconds always zeroed.– Maniero
I get it, then in my java code I pass the value
hh:mm
for variables of the typeDATE
packagejava.sql.date
?– DiegoAugusto
It is, then, there has to see better. In this context it can be interesting to use the
DATETIME
to make it compatible with Java. Even if you have superfluous information. You can usejava.sql.Time
. The decision is not simple. Read this: http://dev.mysql.com/doc/connector-j/en/connector-j-reference-type-conversions.html– Maniero
I’ll try to do it right here
– DiegoAugusto
I managed to do here, the time was saved in this format:
13:00:00.000
but I think it’s okay. Thank you.– DiegoAugusto
I would use the Team too, if in the future you want to order it wouldn’t work with the varchar
– GabrielLocalhost