Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mithridates's avatar

Database Storing time and not date

In a project, I have a table called schedules. this table has 2 fields for storing opening_hour and closing_hour for each venue.
What is proper datatype for storing these fields?

0 likes
4 replies
Mithridates's avatar

Thank you @oeb. do you know difference between dateTime and timestamps in laravel?

oeb's avatar

DATETIME and TIMESTAMP are not laravel things, they are sql data types. There are two main differences between them, but the mysql docs have a comprehensive breakdown here - http://dev.mysql.com/doc/refman/5.6/en/datetime.html

The first, most obvious one is the range. DATETIME supports '1000-01-01 00:00:00' to '9999-12-31 23:59:59' and TIMESTAMP supports '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07'.

The second, and probably the more confusing of the two is that they are stored slightly differently. DATETIME is stored as you specify it, if you say 2015-9-10 9:47:00, that's how it's stored, regardless of your timezone. TIMESTAMP takes your time zone into account and always stores in universal time (UTC which is the time in the UK during winter, when it's not using daylight savings time). So if your time zone is set to, lets say New York, which is UTC - 5, and you store 2015-9-10 9:47:00, it's stored as 2015-9-10 14:47:00. This time zone is normally set by the connection automatically. This can be handy if you are accessing the data from multiple places and you want it to be time zone aware.

3 likes

Please or to participate in this conversation.