MySql Calculate Time age/days with Function and Stored Procedures

Calculate Age with MySQL

You can using mysql calculate age with two way using sotred procdures or with mysql query with calculate two variable date, you can using stored procedures if you alwasy using this function in your project, but if you using calculate age for one more time you can using mysql query to simple.

How to Calculate Age in MySQL with Stored Procedures

with mysql Stored Procedures which allow us to automate or program our way out of many tasks on directly on the server rather than having to write external scripts to do complex manipulation of data. you can only using Store Procdures in Mysql 5.0 or more, with mysql stored procedures  you  can easy calculate age in mysql.

this Stored  Procedures function to calculate time difference or calculate age :

 

  1. – —————————-
  2. – Function structure for umur
  3. – —————————-
  4. DROP FUNCTION IF EXISTS `age`;
  5. DELIMITER ;;
  6. CREATE DEFINER=`root`@`localhost` FUNCTION `age`(birth DATE, NOW DATE) RETURNS INT(11)
  7. BEGIN
  8.   RETURN FROM_DAYS(TO_DAYS(tglskrg)TO_DAYS(tgllahir));
  9.   END;;
  10. DELIMITER ;

to used this procedures you can call store procedures function  :

 

  1. age (birthdate, nowdate) ;

How to Calculate Age in MySQL with query

now what i can i do with mysql query for calculate total age to simple used you can using mysl query to calculate age like this :

 

  1. (YEAR(CURDATE())YEAR(`b`.`birthdate`)) as age_year
  2. (MONTH(NOW())MONTH(`b`.`birthdate`)) AS age_mounth
  3. (DAY(NOW())DAY(`b`.`birthdate`)) AS age_day
  1.  
  1.  

1# line mysql calculate year
2# line mysql calculate mounth
3# line mysql calculate days

you can using mysql calculate time difference year, mounty and days with this query.

Posted by admin   @   31 October 2009

2 Comments

Comments
Nov 8, 2009
4:16 pm

nice i love it

Nov 8, 2009
4:17 pm

I miss something

Leave a Comment

Name

Email

Website

Previous Post
« CSS manipulation | crate spreadsheet form using css
Next Post
jquery image slider | slideshow Images and Content »
Powered by Wordpress   |   Lunated designed by ZenVerse
Top Footer