K
K
kapai692015-04-11 20:51:49
MySQL
kapai69, 2015-04-11 20:51:49

How to make a selection of the nearest birthdays?

There are fields with dates, you need to display three fields starting with today and sorted in the correct order.
Raw data:
1955-01-02
1966-02-06
1984-02-12
1976-03-10
1999-04-04
1958-11-02
Should be:
1958-11-02
1955-01-02
1966-02- 06
What would the request look like?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2015-04-11
@alexey-m-ukolov

select birthday
from some_table
order by dayofyear(birthday - interval dayofyear(now()) -1 day) asc
limit 3

Like this. Unless, of course, your date of birth field is of the correct type.

A
Alexander, 2015-04-13
@wiggle

select birthday
from some_table
where date(birthday) <= now()
order by date(birthday) desc
limit 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question