DELIMITER //
DROP PROCEDURE IF EXISTS usia//
CREATE PROCEDURE usia(IN lahir DATE, OUT umur INT,OUT bulan INT,OUT hari INT,OUT jam INT)
BEGIN
SET umur=
DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(lahir, '%Y') -
(DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(lahir, '00-%m-%d'));
SET bulan =
DATE_FORMAT(NOW(), '%m') - DATE_FORMAT(lahir, '%m') -
(DATE_FORMAT(NOW(), '%Y-00-%d') < DATE_FORMAT(lahir, '%Y-00-%d'));
SET hari =
DATE_FORMAT(NOW(), '%d') - DATE_FORMAT(lahir, '%d') -
(DATE_FORMAT(NOW(), '%Y-%m-00') < DATE_FORMAT(lahir, '%Y-%m-00'));
END//
SET @lahir='2013-12-14';
SET @umur = '';
SET @bulan = '';
SET @hari = '';
SET @jam = '';
CALL usia(@lahir,@umur,@bulan,@hari,@jam);
SELECT @umur AS Umur,@bulan AS Bulan,@hari AS Hari;
Sunday, December 15, 2013
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment