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 7534917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:09:21+00:00 2026-05-30T06:09:21+00:00

I am creating a Stored procedure in which , I am passing 2 IN

  • 0

I am creating a Stored procedure in which ,

I am passing 2 IN parameters as ‘year’ & ‘month’ to a procedure,

then ” I need to store these both IN parameters in one variable in date_format like (‘YYYY-MM-DD’).”

And after that I want to use that variable with that Date_Format.

I will try to explain above things in stored procedures format

CREATE PROCEDURE build_table(IN years CHAR(5) ,IN months CHAR(4))
BEGIN
DECLARE format1 date ;

# Now i want to store both IN parameters in 'format1' variable and then format1 should be in format 'YYYY-MM-DD' 

Can I do this in stored procedure?

If yes give me some guidance.

  • 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-30T06:09:22+00:00Added an answer on May 30, 2026 at 6:09 am

    Tru to use this variant –

    SET @year = 2012;
    SET @month = 2;
    SELECT STR_TO_DATE(CONCAT(@year, '-', @month), '%Y-%c');
    

    The STR_TO_DATE function will help you to make a date value. Change @year and @month variables with IN parameters.

    Then you can use a DATE_FORMAT function to format datetime value, e.g.:

    SET @year = 2012;
    SET @month = 2;
    SET @dt = STR_TO_DATE(CONCAT(@year, '-', @month), '%Y-%c');
    SELECT DATE_FORMAT(@dt, '%m/%d/%Y');
    +------------------------------+
    | DATE_FORMAT(@dt, '%m/%d/%Y') |
    +------------------------------+
    | 02/00/2012                   |
    +------------------------------+
    

    CREATE PROCEDURE build_table(IN years CHAR(5), IN months CHAR(4))
    BEGIN
      DECLARE format1 date;
      SET format1 = DATE_SUB(STR_TO_DATE(CONCAT(years, '-', months, '-01'), '%Y-%c-%e'), INTERVAL 1 DAY);
    
    
      SELECT format1;
    END
    
    CALL build_table(2012, 1);
    +------------+
    | format1    |
    +------------+
    | 2011-12-31 | -- default format is 'YYYY-MM-DD'
    +------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a stored procedure to which I want to pass as variable
I'm creating a stored procedure to return search results where some of the parameters
I am creating an application in which i am using stored procedure where i
I am creating a stored procedure which has to create a table which name
I am creating a stored procedure in MySQL 5.1.40 which needs to run a
For one of our recent projects, we created a stored procedure which generated SQL
I am creating a report with the data which calls the stored procedure and
I am creating as stored procedure that brings back a bunch of data that
I was creating a stored procedure and I see some differences between my methodology
How to write a query for creating an stored procedure in mysql

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.