DELIMITER //
DROP PROCEDURE IF EXISTS lagi_berapahari//
CREATE PROCEDURE lagi_berapahari(IN lahir DATE, OUT birthday_berikut VARCHAR(50), OUT berapa_hari INT)
BEGIN
SET birthday_berikut=
IF((MONTH(NOW()))>MONTH(lahir),
CONCAT (YEAR(NOW())+1,'-',MONTH(lahir),'-', DAY(lahir)),
IF(DAY(NOW())>DAY(lahir), CONCAT(YEAR(NOW())+1,'-',MONTH(lahir),'-',DAY(lahir)),
CONCAT(YEAR(NOW()),'-',MONTH(lahir),'-',DAY(lahir))));
SET @tmp = birthday_berikut;
SET berapa_hari = DATEDIFF(@tmp,CURDATE());
END//
SET @lahir='2013-12-19';
SET @birthday_berikut = '';
SET @berapa_hari='';
CALL lagi_berapahari(@lahir,@birthday_berikut,@berapa_hari);
SELECT DATE_FORMAT(@birthday_berikut, "%e-%b-%Y") AS ultah_berikut,@berapa_hari AS lama;
Procedure Menghitung Lama ULTAH
Labels:
Basis Data Lanjut
0 comments:
Post a Comment