给你两套代码,分别以当日为基准日,以日期文本参数组件设定的日期为基准日
// 下面是以当天日期为例,计算得出对应的开始日和结束日
if (weekday(now(),2) == 1) {
debug("开始日:" + formatDate(dateAdd(now(),"dayofyear",-10),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(now(),"dayofyear",-4),"yyyy-MM-dd"))
}
if (weekday(now(),2) == 2) {
debug("开始日:" + formatDate(dateAdd(now(),"dayofyear",-11),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(now(),"dayofyear",-5),"yyyy-MM-dd"))
}
if (weekday(now(),2) == 3) {
debug("开始日:" + formatDate(dateAdd(now(),"dayofyear",-12),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(now(),"dayofyear",-6),"yyyy-MM-dd"))
}
if (weekday(now(),2) == 4) {
debug("开始日:" + formatDate(dateAdd(now(),"dayofyear",-13),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(now(),"dayofyear",-7),"yyyy-MM-dd"))
}
if (weekday(now(),2) == 5) {
debug("开始日:" + formatDate(dateAdd(now(),"dayofyear",-7),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(now(),"dayofyear",-1),"yyyy-MM-dd"))
}
if (weekday(now(),2) == 6) {
debug("开始日:" + formatDate(dateAdd(now(),"dayofyear",-8),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(now(),"dayofyear",-2),"yyyy-MM-dd"))
}
if (weekday(now(),2) == 7) {
debug("开始日:" + formatDate(dateAdd(now(),"dayofyear",-9),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(now(),"dayofyear",-3),"yyyy-MM-dd"))
}
// 以文本参数1的日期为例,计算文本参数组建中设置的任何日期对应的开始日和结束日
var a = 文本参数1.value
if (weekday(parseDate(a,"yyyy-MM-dd"),2) == 1) {
debug("开始日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-10),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-4),"yyyy-MM-dd"))
}
if (weekday(parseDate(a,"yyyy-MM-dd"),2) == 2) {
debug("开始日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-11),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-5),"yyyy-MM-dd"))
}
if (weekday(parseDate(a,"yyyy-MM-dd"),2) == 3) {
debug("开始日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-12),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-6),"yyyy-MM-dd"))
}
if (weekday(parseDate(a,"yyyy-MM-dd"),2) == 4) {
debug("开始日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-13),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-7),"yyyy-MM-dd"))
}
if (weekday(parseDate(a,"yyyy-MM-dd"),2) == 5) {
debug("开始日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-7),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-1),"yyyy-MM-dd"))
}
if (weekday(parseDate(a,"yyyy-MM-dd"),2) == 6) {
debug("开始日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-8),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-2),"yyyy-MM-dd"))
}
if (weekday(parseDate(a,"yyyy-MM-dd"),2) == 7) {
debug("开始日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-9),"yyyy-MM-dd"))
debug("结束日:" + formatDate(dateAdd(parseDate(a,"yyyy-MM-dd"),"dayofyear",-3),"yyyy-MM-dd"))
}
|