0

I'm looking to setup a calendar date stored procedure in Mysql. The purpose is to be able to select the first day and last day of a given month by call the procedure. I know it is probably a very simple thing that I am missing. Below is what I have tried.

CREATE PROCEDURE CalendarDate
        @startdate DATE,
        @enddate DATE
    AS
SELECT
    (SELECT DATE_ADD(DATE_ADD(LAST_DAY(CURDATE()),interval 1 DAY),interval -1 MONTH)) AS startdate
,   (SELECT LAST_DAY(CURDATE())) AS enddate
;

I would like to use the above to be able run a query by just saying:

SELECT *
FROM mytable
WHERE action_date BETWEEN @startdate AND @ endate
Leon Claassen
  • 183
  • 3
  • 12
  • For MySQL - this procedure code is synthactically wrong. – Akina Feb 10 '20 at 09:34
  • 1
    I'm slightly baffled - you CALL a stored procedure - you cannot use an sp in a select – P.Salmon Feb 10 '20 at 09:34
  • Assuming you'd execute SP then use variables values assigned in your query - SP and query MUST be executed in the same connection (and without reconnection between statements!). – Akina Feb 10 '20 at 09:37
  • I see nothing 'procedural' about this problem – Strawberry Feb 10 '20 at 09:40
  • Please look answer at https://stackoverflow.com/questions/11808232/how-do-i-select-between-the-1st-day-of-the-current-month-and-current-day-in-mysq – Slava Rozhnev Feb 10 '20 at 13:24
  • Does this answer your question? [How do I select between the 1st day of the current month and current day in MySQL?](https://stackoverflow.com/questions/11808232/how-do-i-select-between-the-1st-day-of-the-current-month-and-current-day-in-mysq) – Slava Rozhnev Feb 10 '20 at 13:25

0 Answers0