MySQL Forums
Forum List  »  Stored Procedures

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
11375
October 06, 2016 07:58AM


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.