Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7524155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:00:38+00:00 2026-05-30T03:00:38+00:00

I am trying to create a stored procedure that when given a month value,

  • 0

I am trying to create a stored procedure that when given a month value, returns the user the last day of the month.

So far:

DROP PROCEDURE IF EXISTS getLastDayMonth$$
CREATE PROCEDURE getLastDayMonth(IN inMonth int) 
BEGIN
    SELECT LAST_DAY(inMonth);
END $$

I am having trouble figuring out how i can make inMonth a parameter that the sql function Last_DAY accepts. Is there another function that takes in an int as a month and returns the last day of the month? I am trying to avoid giving a DATE type as a paramater

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:00:41+00:00Added an answer on May 30, 2026 at 3:00 am

    You can add moths to first year day and get last_date:

    SELECT LAST_DAY( DATE_ADD( '2012-01-01 00:00:00',  
                               INTERVAL inMonth - 1 MONTH) 
                   );
    

    Alternative solution is ELT function:

    SELECT cast( 
             ELT(inmonth, '31', '28', '31', '30', '31', .... ,'31' )
             as SMALLINT 
           ) as last_day
    

    The last one, use case statement:

    SELECT case inmonth
            when 1 then 31
            when 2 then 29
            ...
            when 12 then 31
           end as last_day
    

    EDITED

    mysql> CREATE PROCEDURE getLastDayMonth(IN inMonth int)
        -> begin
        -> SET @t=inMonth -1;
        -> SELECT LAST_DAY( DATE_ADD( '2012-01-01 00:00:00',INTERVAL @t MONTH));
        -> end@@
    Query OK, 0 rows affected (0.24 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

2 Hi! I am trying to create stored procedure that gone return varchar value,
I am trying to create a stored procedure that returns the ID of a
I'm trying to create a stored procedure that uses SELECT TOP 20 * from
I am trying to create a stored procedure that has optional parameters. I followed
I'm trying to create a stored procedure that retrieves data from 3 tables on
I'm trying to create a stored procedure to retrieve value from multiple. The problem
I'm trying to write a stored procedure that will create a new FILEGROUP based
I am trying to create a stored procedure that takes a bit parameter which
I am trying to create a Stored Procedure that will be used for a
I am trying to write a stored procedure that checks if a value exist,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.