M
M
Michael2019-08-18 15:49:32
Yii
Michael, 2019-08-18 15:49:32

What is the best way to store the date in the DB when using the DateTimePicker widget?

Hello everybody! I understand that the question is not new, and similar questions have already been received a lot, but I'll ask anyway. When using the DateTimePicker widget from kartik, what is the best type of field in the database to use to store the date - integer, datetime or timestamp? What type of field do you use in your practice?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-08-18
@Bally

1. The widget from the card has nothing to do with it! Fields in the database can differ greatly from visualization and usage.
2. Looking for what purposes you need to use the date.
TIMESTAMP is 4 bytes
DATETIME is 8 bytes
Timestamps are also lighter in the database and index faster.
The DATETIME type is used when you need values ​​that contain both date and time. MySQL retrieves and displays DATETIME values ​​in the format "YYYY-MM-DD HH:MM:SS". Supported range: 1000-01-01 00:00:00 to 9999-12-31 23:59:59 .
The TIMESTAMP type has a range of 1970-01-01 00:00:01UTC until 2038-01-09 03:14:07 UTC. It has different properties depending on the version of MySQL and the SQL mode the server is running in.
DATETIME is constant while TIMESTAMP is determined by the time_zone setting .
I make this decision on a semantic basis.
I use a timestamp (TIMESTAMP) when I need to record a (more or less) fixed point in time . For example, when a record was inserted into the database, or when some user action took place.
I am using a date and time field (DATETIME) where the date and time can be set and changed arbitrarily. For example, when the user can later save changes.
ARTICLE ON THE TOPIC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question