当前位置: 数据库>mysql
探讨如何计算age的sql函数
来源: 互联网 发布时间:2014-10-09
本文导语: 代码如下:ALTER FUNCTION [dbo].[get_FullAge]( @birthday datetime, @currentDay datetime)RETURNS INTASBEGINDECLARE @age INTSET @age = DATEDIFF(YEAR, @birthday, @currentDay)IF DATEDIFF(DAY, DATEADD(YEAR, @age, @birthday), @currentDay)
代码如下:
ALTER FUNCTION [dbo].[get_FullAge]
(
@birthday datetime, @currentDay datetime
)
RETURNS INT
AS
BEGIN
DECLARE @age INT
SET @age = DATEDIFF(YEAR, @birthday, @currentDay)
IF DATEDIFF(DAY, DATEADD(YEAR, @age, @birthday), @currentDay)