生日从数据库开始倒数(距离当前日期仅剩几天) [英] birthday count down from database (only days left from current date)

查看:61
本文介绍了生日从数据库开始倒数(距离当前日期仅剩几天)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我如何从数据库中获得剩余的日子.我的意思是说我们有用户数据库,其中有列名DOB.我只想知道从当前日期到生日还有几天.

Any one to help me how i can get left days from the database. I mean to say we have database of user there is column name DOB. i just want to know how many days left for his birthday from current date.

推荐答案

在SQL中尝试一下.
Try this in SQL.
DECLARE @BirthDay smalldatetime
SET @BirthDay = ''2011-08-21''

SELECT DATEDIFF(day, CURRENT_TIMESTAMP, DATEADD(year, DATEDIFF(year, @BirthDay, CURRENT_TIMESTAMP)
       + CASE WHEN DATEADD(year, DATEDIFF(year, @BirthDay, CURRENT_TIMESTAMP), @BirthDay) < CURRENT_TIMESTAMP 
       THEN 1 ELSE 0 END, @BirthDay))


尝试
SELECT DATEDIFF(day, birthDate, SysDateTime());



有关DateDiff的更多信息,请参见此处 [



For more information on DateDiff, see here[^].


这篇关于生日从数据库开始倒数(距离当前日期仅剩几天)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆