Answer the question
In order to leave comments, you need to log in
How to do date check?
Good day, I have a question:
there is a table:
id | name | start_date | end_date
1 | act1 | 2018-02-15 00:00:00 | 2018-04-05 00:00:00
1 | act2 | NULL | 2018-04-23 00:00:00
1 | act3 | 2018-02-12 00:00:00 | 2018-02-28 00:00:00
1 | act4 | 2018-03-11 00:00:00 | 2018-04-05 00:00:00
1 | act5 | 2018-02-15 00:00:00 | 2018-02-20 00:00:00
Answer the question
In order to leave comments, you need to log in
SELECT 'Active Action' as `type`, * FROM `table` WHERE `start_date` IS NULL OR (NOW() BETWEEN `start_date` AND `end_date`)
UNION
SELECT 'Upcoming Action' as `type`, * FROM `table` WHERE `start_date` > NOW();
Try using if or case like this:
SELECT CASE <variable> WHEN <value> THEN <returnvalue>
WHEN <othervalue> THEN <returnthis>
ELSE <returndefaultcase>
END AS <newcolumnname>
FROM <table>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question