php中计算离生日还剩下多少天
2个回答
2014-12-08
展开全部
declare @t table(id int identity(1,1),出生日期 datetime)
insert into @t(出生日期)
select '1985-09-3'
union all select '1977-09-04'
union all select '1978-11-25'
union all select '1979-11-26'
union all select '1987-11-27'
union all select '1999-11-28'
union all select '1999-11-29'
union all select '1999-11-30'
select * from(
select *,天数=datediff(day,getdate(),dateadd(year,year(getdate())-year(出生日期),出生日期))
from @t) a
/*
id 出生日期 天数
----------- ----------------------- -----------
1 1985-09-03 00:00:00.000 0
2 1977-09-04 00:00:00.000 1
3 1978-11-25 00:00:00.000 83
4 1979-11-26 00:00:00.000 84
5 1987-11-27 00:00:00.000 85
6 1999-11-28 00:00:00.000 86
7 1999-11-29 00:00:00.000 87
8 1999-11-30 00:00:00.000 88
(8 行受影响)
*/
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询