S
S
SoloMidPlzD2016-04-16 17:39:15
PHP
SoloMidPlzD, 2016-04-16 17:39:15

SQL SELECT WHERE DATETIME = $year?

The table has an attribute called birthday.
You need to select those who were born in $year.
That is, if there is an entry birthday = 1995-05-07, and $year = 1995 Then it should get into the select.
ps Need the fastest implementation. I don’t know if it’s worth creating a separate year attribute if there is already a datetime ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kovalsky, 2016-04-16
@SoloMidPlzD

dev.mysql.com/doc/refman/5.5/en/date-and-time-func... Hold on. Can you guess how to use it or write a script?
UPD: On large volumes of rows - the use of such functions can mess up the query-plan a little. Alternatively, if you want to try to compare performance - you can try to make a selection like

WHERE birthday BETWEEN '1995-01-01' AND '1995-12-31'

M
mistergonza, 2016-04-16
@mistergonza

SELECT YEAR(birthday) as year FROM blabla WHERE year = '1995';

But a separate column will be faster

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question