MySQL Forums :: Stored Procedures :: Procedure passed Datetime parameter problem


Advanced Search

Procedure passed Datetime parameter problem
Posted by: Thomas Gruener ()
Date: October 06, 2016 07:58AM

Hi,
I have a stored procedure in which I pass a datetime parameter. but for some reason it won't recognice it.
The parameter firstDate is passed, but when I try to set the new value for it I get either 'NULL' or '0000-00-00 00:00:00' as output for it. Why is that?

call sp_Month_Daily_Total_Count_Person(null);
I get: '0000-00-00 00:00:00', NULL as answer????

So how can I pass in a datetime value and change it like to the first of the month????

Here is my Code:
CREATE DEFINER=`root`@`%` PROCEDURE `sp_Month_Daily_Total_Count_Person`(IN firstDate DATETIME)
BEGIN
-- set date to first and last day of month
IF firstDate IS NULL THEN
SET firstDate := DATE_FORMAT(NOW(), '01-%m-%Y');
ELSE
SET firstDate := CONCAT(DATE_FORMAT(STR_TO_DATE(firstDate, '%d-%m-%Y'), '01-%m-%Y'));
END IF;

SET @last := CONCAT(DATE_FORMAT(LAST_DAY(STR_TO_DATE(firstDate, '%d-%m-%Y')), '%d-%m-%Y 23:59:59'));
SELECT firstDate AS First, @last as Last;
END


Thanks for any help.

Options: ReplyQuote


Subject Views Written By Posted
Procedure passed Datetime parameter problem 2062 Thomas Gruener 10/06/2016 07:58AM
Re: Procedure passed Datetime parameter problem 284 Peter Brawley 10/06/2016 11:53AM
Re: Procedure passed Datetime parameter problem 265 Thomas Gruener 10/12/2016 03:05AM
Re: Procedure passed Datetime parameter problem 229 Peter Brawley 10/12/2016 11:58AM
Re: Procedure passed Datetime parameter problem 199 Rick James 10/17/2016 04:10PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.