日期表达式 - 在运算符中 [英] Date expression- In operator
问题描述
如果我在4月1日至5日之间选择我的日期参数,我应该到2月2日(2/28)的最后一个工作日,如果我的日期参数是4月6日到5月5日,它应显示最后一次工作3月3日(3/29)..等等
If I select my date parameter in between 1-5 of April, I should get the last working day of february(2/28) and if my date parameter is 6 April to May 5 it should display last working day of march(3/29).. and so on
例如:我选择4月3日作为我的参数,我的输出中应该得到2/28
   我选择从4月6日到5月5日的任何日期作为我的参数,我的输出中应该得到3/29
    我选择5月3日 作为我的参数,我的输出中应该得到3/29,依此类推¥b $ b $
我将表达式作为
eg: I select 3rd of April as my parameter, I should get 2/28 in my output
I select any date from 6th April until 5th May as my parameter, I should get 3/29 in my output
I select 3rd of May as my parameter, I should get 3/29 in my output and so on
and I gave my expression as
potdate在这里是我的参数..这只给我前几个月的最后一个工作日期。请帮助
potdate is my parameter here.. This gives me only the previous months last working date. Please help
Prathyusha
Prathyusha
推荐答案
嗨kpkasam
Hi kpkasam
很抱歉不清楚其他日期的映射值,只是根据当前信息,您尝试使用以下数据集查询来获取对应日期。 (如果你想使用表达式,似乎很复杂)
Sorry for not clear about the other date ‘s mapping value , just according to the current information , you oculd try to use the following dataset query to get the correspond date. (seems little complex if you want to use expression )
参见:
declare @weeknumber as int
declare @decresenumber as int
declare @lastmonthdate as date
declare @lastdate as date
if @potdate>='2019.4.1' and @potdate<='2019.4.5'
set @lastmonthdate= DATEADD(MONTH, DATEDIFF(MONTH, -2, @potdate)-2, -2)
select @weeknumber = DATEPART(WEEKDAY, @lastmonthdate)
set @decresenumber = (@weeknumber+1)%7
if (@decresenumber in (0,3,4,5,6) )
select @lastmonthdate as lastdate;
if (@decresenumber in (1,2))
select @lastdate = dateadd(day , 0-@decresenumber,@lastmonthdate)
if @potdate>='2019.4.6' and @potdate <= '2019.5.5'
set @lastmonthdate= DATEADD(MONTH, DATEDIFF(MONTH, -1, @potdate)-1, -1)
select @weeknumber = DATEPART(WEEKDAY, @lastmonthdate)
set @decresenumber = (@weeknumber+1)%7
if @decresenumber in (0,3,4,5,6)
select @lastmonthdate as lastdate;
if (@decresenumber in (1,2))
select @lastdate = dateadd(day , 0-@decresenumber,@lastmonthdate)
select @lastdate as lastdate
希望它可以帮助你。
最好的问候,
Eric Liu
这篇关于日期表达式 - 在运算符中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!