如何根据currentdate(getdate())获取年份期间取决于加入日期。 [英] How to get the year period as per the currentdate(getdate()) depend upon joining date.
本文介绍了如何根据currentdate(getdate())获取年份期间取决于加入日期。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何按照当前日期(GetDate())获取年度期间取决于加入日期。
例如。
Hi,
How to get the Year Period as per the currentDate(GetDate()) depend upon Joining Date.
For Example.
Emp_No Joining Date As per todaycurrentDate(His One year period End)
1 14-Jul-2013 14-Jul-2017
2 14-Jul-2016 14-Jul-2017
3 01-Feb-2015 01-Feb-2017
如何进行查询?
我尝试过:
我使用的是这个但不适合这个。
加入日期时的情况< GetDate()THEN dateadd(DAY,365,JoinDate)ELSE JoinDate END
谢谢
Basit。
How to do the query?
What I have tried:
I use the case but this one will not suite.
CASE WHEN JoinDate < GetDate() THEN dateadd(DAY , 365 , JoinDate) ELSE JoinDate END
Thanks
Basit.
推荐答案
尝试:
Try:
CASE WHEN JoinDate < GetDate() THEN DATEFROMPARTS(DATEPART(yy, GETDATE()), DATEPART(mm, JoinDate), DATEPART(dd, JoinDate)) ELSE JoinDate END
不知道,有什么问题你的解决方案除了闰年没有365天。如果我写这个查询它会是这样的
Don't know, what's wrong with your solution except that leap years does'nt have 365 days. If I would write that query it would look like this
SELECT [Emp_No]
, [JoinDate]
, CASE
WHEN ([JoinDate] < getdate()) THEN DATEADD(YEAR, 1, [JoinDate])
ELSE [JoinDate]
END AS [PeriodEnd]
FROM [dbo].[<Tablename>]
这篇关于如何根据currentdate(getdate())获取年份期间取决于加入日期。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文