G
G
Greg Popov2017-04-24 20:29:41
MySQL
Greg Popov, 2017-04-24 20:29:41

Why doesn't the select work?

I want to select:
All events for the current month, what's wrong?

SELECT * FROM `event` WHERE MONTH(ends_at) = MONTH(CURRENT_TIMESTAMP)

All events for the current week
SELECT * FROM `event` WHERE ends_at <= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY AND ends_at > curdate() - INTERVAL DAYOFWEEK(curdate()) - 1 DAY

All events for today
SELECT * FROM `event` WHERE DATE(ends_at) >= CURDATE()

Where is the mistake?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Greg Popov, 2017-05-04
@Gregpopov

I forgot that this is a timestamp, and therefore:YEARWEEK(FROM_UNIXTIME(starts_at))

N
NikitoZ Sc., 2017-05-04
@Niki-Z

Is it possible to see at least a couple of lines from the 'event' table?
In theory, everything is correct if the ends_at field is of type date or datetime

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question