检查生日是在接下来的'n'天 [英] check birhtday is in next ' n' days

查看:74
本文介绍了检查生日是在接下来的'n'天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码检查出生日期是否在接下来的30天内,可以正常使用,但是当前日期是否在12月&生日是一月份的月份,它不起作用

I used the below code to check whether date of birth is in upcoming 30 days,it is working fine but if current date is in december month & birthday is in january month it is not working

if datepart(dayofyear, @DateofBirth) between datepart(dayofyear,getdate()) and datepart(dayofyear, dateadd(day,30,getdate()))



如何解决该问题?

[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]



how to fix the problem?

[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]

推荐答案

好吧,嗯. DayOfYear表示一年中的天数.因此,如果您的生日在12月,则datepart(dayofyear,dateadd(day,30,getdate()))将介于1到31之间.如果您不能弄清楚它的作用.

如果getdate()返回12月的日期,则需要在第二个值中加上365,因为否则,您将询问(350)是否在(345)和(5)之间或类似.
Well, duh. DayOfYear means number of days in the year. So, datepart(dayofyear, dateadd(day,30,getdate())) will be between 1 and 31 if your birthday is in Dec. You should try thinking about your code, or running sections of it, if you can''t work out what it does.

If getdate() returns a date in Dec, you need to add 365 to the second value, because otherwise you''re asking if (350) is between (345) and (5), or similar.


你好

从tblBirthDay选择ID,EmpName,substring((convert(varchar,DoB,107)),0,7)作为DoB,ImagePath,其中datepart(dayofyear,getdate())和datepart(dayofyear,dateadd之间的datepart(dayofyear,DOB) (day,7,getdate()))



试试这个,这对我有用.这是从今天开始的一周内的一天,您可以更改30天.


谢谢
sanjeev
hello

select ID,EmpName,substring((convert(varchar,DoB,107)),0,7) as DoB,ImagePath from tblBirthDay where datepart(dayofyear,DOB) between datepart(dayofyear,getdate()) and datepart(dayofyear, dateadd(day,7,getdate()))



try this this is working for me. this is for with in week from today b''day you can change for 30 days.


thanks
sanjeev


这篇关于检查生日是在接下来的'n'天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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