E
E
Eugene Ordinary2016-09-06 12:42:54
MySQL
Eugene Ordinary, 2016-09-06 12:42:54

What is the best way to store a birthday in MySQL?

It is necessary to make it possible to indicate in the questionnaire separately the year of birth, separately the day of birth (day + month), and with the possibility of not specifying one of the parameters, as well as with a search by range, for example, from October 3 to November 13. What is the best way to keep a birthday? If DATE, then an unnecessary year will be stored there, and it must be selected as a leap year so that February 29 is recorded. And it's hard to compare values.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
evnuh, 2016-09-06
@evnuh

Birthday (year, month, day) is better stored in DATE, obviously. Do not break them into columns, but operate on the data inside the database.

R
Rou1997, 2016-09-06
@Rou1997

UNIX TIMESTAMP as an option.

E
Edward, 2016-09-06
@edb

store it as char(8) YYYYMMDD
for missing data set to 0, if data is complete then run checks. Such dates can also be stored separately in DATE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question