Calculate Age or Birthday
CREATE or replace FUNCTION CalculateAge(m_birthday date, m_datetoday date)
RETURNS INTEGER
AS
$$
BEGIN
RETURN
(
select
(
CASE
WHEN dateadd('y', datediff ('y', m_birthday, m_datetoday), m_birthday) > m_datetoday
THEN datediff ('y', m_birthday, m_datetoday) - 1
ELSE datediff ('y', m_birthday, m_datetoday)
END)
);
END;
$$ language 'plpgsql';
-- see my previous post on dateadd and datediff
Labels: functions, mssql-compatible functions
1 Comments:
this is so awesome . thanks .
4:28 PM
Post a Comment
<< Home