1

I need to run an event weekly (every 1st Friday of the month) and another event every Friday other than the first Friday of the month. All I could think of was something like

IF WEEKDAY()=4 AND DAYOFMONTH() BETWEEN 1 AND 7 THEN ....

and

IF WEEKDAY()=4 AND DAYOFMONTH() BETWEEN 8 AND 31 THEN ....

But is there a better/more neat query that?

popkutt
  • 949
  • 3
  • 10
  • 19
  • Try using cron jobs or a MySQL event scheduler, otherwise you would need to run the event manually. Here is a [post](https://stackoverflow.com/questions/21196613/run-a-mysql-query-as-a-cron-job) about the topic. – squancy Jun 03 '18 at 11:24

1 Answers1

2
SET @x := '2018-06-01';

SELECT CASE WHEN WEEKDAY(@x) = 4 
            THEN CASE WHEN DAYOFMONTH(@x) < 8 
                      THEN 'FIRST FRIDAY' 
                      ELSE 'SOME OTHER FRIDAY' END 
            ELSE 'NOT FRIDAY' END x;
+--------------+
| x            |
+--------------+
| FIRST FRIDAY |
+--------------+




SET @x := '2018-06-08';

SELECT CASE WHEN WEEKDAY(@x) = 4 
            THEN CASE WHEN DAYOFMONTH(@x) < 8 
                      THEN 'FIRST FRIDAY' 
                      ELSE 'SOME OTHER FRIDAY' END 
            ELSE 'NOT FRIDAY' END x;
+-------------------+
| x                 |
+-------------------+
| SOME OTHER FRIDAY |
+-------------------+

SET @x := '2018-06-07';

SELECT CASE WHEN WEEKDAY(@x) = 4 
            THEN CASE WHEN DAYOFMONTH(@x) < 8 
                 THEN 'FIRST FRIDAY' 
                 ELSE 'SOME OTHER FRIDAY' END 
            ELSE 'NOT FRIDAY' END x;
+------------+
| x          |
+------------+
| NOT FRIDAY |
+------------+
Strawberry
  • 33,750
  • 13
  • 40
  • 57