如何获得上周日的日期?

时间:2019-11-23 06:01:30

标签: date google-sheets google-sheets-formula array-formulas weekday

我需要在一个单元格中显示上周日的日期,以便在Google表格上创建每周报告。我一直在寻找解决方案,而我找到的最接近的是:

=TODAY()+(7-WEEKDAY(TODAY(),3))

但这给出了下周一的日期。知道如何修改它以显示上周日的日期吗?或者,您还有另一种解决此问题的方法吗?

3 个答案:

答案 0 :(得分:1)

您要查找的公式是:

(..)

根据您要在“上周日”采取的措施,您可以简化/分解这一点:

如果您将“最后一个星期日”表示为“最近发生的星期日:”

=DATE(YY, MM, DD) - (WEEKDAY(DATE(YY, MM, DD)) - 1) - 7

// OR

=TODAY() - (WEEKDAY(TODAY()) - 1) - 7

如果您将“最后一个星期日”表示为“上一周发生的星期日:”

=DATE(A2,B2,C2) - WEEKDAY(DATE(A2,B2,C2)) + 1

正在处理:

=DATE(A4,B4,C4) - WEEKDAY(DATE(A4,B4,C4)) - 6

希望这种解释可以解释末尾的数字。 =TODAY() - (WEEKDAY(TODAY()) - 1) - 7 TODAY() // get today's date, ie. 22/11/2019 WEEKDAY(TODAY()) // get the current day of the week, ie. 6 (friday) - // take the first date and subtract that to rewind through the week, // ie. 16/11/2019 (last saturday, since saturday is 0) - 1 // rewind back one less than the entire week // ie. 17/11/2019 (this sunday) - 7 // rewind back to the sunday before this // sunday, ie. 10/11/2019 带您从上周的星期六到当前周的星期日(我称为“本周日”),+ 1带您回到上周,回到我所谓的“最后一个”星期日。”


查看此处:

Google Sheets Example


答案 1 :(得分:1)

尝试:

=ARRAYFORMULA(TO_DATE(FILTER(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))), 
 TEXT(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))), "ddd")="Sun")))

0


如果今天是星期天,而您仍然希望最后一个星期日,那么:

=ARRAYFORMULA(IF(TEXT(TODAY(), "ddd")="Sun", TODAY()-6, 
 TO_DATE(FILTER(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))), 
 TEXT(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))), "ddd")="Sun"))))

0

答案 2 :(得分:0)

使用 monday 作为 1 个索引,这将返回上一个星期日或今天(如果是星期日)

=if((7-WEEKDAY(today(),2))>0,today()-(7-(7-WEEKDAY(today(),2))),today()+(7-WEEKDAY(today(),2)))

可以通过在模式存在的三个地方直接更改“-WEEKDAY(today(),2)”之前的数字“7”来选择一周中的其他几天。