如何获得上周日的日期?
How to get last Sunday's date?
我需要在 google 工作表上创建的每周报告的单元格中显示上周日的日期。我一直在谷歌上寻找解决方案,我找到的最接近的是:
=TODAY()+(7-WEEKDAY(TODAY(),3))
但这给出了下周一的日期。知道如何修改它以显示上周日的日期吗?或者,您有其他方法可以解决这个问题吗?
您要查找的公式为:
=DATE(YY, MM, DD) - (WEEKDAY(DATE(YY, MM, DD)) - 1) - 7
// OR
=TODAY() - (WEEKDAY(TODAY()) - 1) - 7
取决于你想成为什么 "last Sunday," 你可以 simplify/factor 这个:
如果你把"last Sunday"理解为"the Sunday which has most recently happened:"
=DATE(A2,B2,C2) - WEEKDAY(DATE(A2,B2,C2)) + 1
如果你把"last Sunday"理解为"the Sunday which took place during the previous week:"
=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
带你从上周的周六到本周的周日(我称之为 "this Sunday"),- 6
带你回到上周我称之为 "last Sunday."
看这里:
尝试:
=ARRAYFORMULA(TO_DATE(FILTER(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))),
TEXT(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))), "ddd")="Sun")))
如果今天是星期天,而您仍然想要最后一个星期天,那么:
=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"))))
使用星期一作为 1 索引,这将 return 前一个星期日或今天(如果是星期日)
=if((7-WEEKDAY(today(),2))>0,today()-(7-(7-WEEKDAY(today(),2))),today()+(7-WEEKDAY(today(),2)))
可以 select 通过在模式存在的三个地方直接更改“-WEEKDAY(today(),2)”之前的数字“7”来 select。
我需要在 google 工作表上创建的每周报告的单元格中显示上周日的日期。我一直在谷歌上寻找解决方案,我找到的最接近的是:
=TODAY()+(7-WEEKDAY(TODAY(),3))
但这给出了下周一的日期。知道如何修改它以显示上周日的日期吗?或者,您有其他方法可以解决这个问题吗?
您要查找的公式为:
=DATE(YY, MM, DD) - (WEEKDAY(DATE(YY, MM, DD)) - 1) - 7
// OR
=TODAY() - (WEEKDAY(TODAY()) - 1) - 7
取决于你想成为什么 "last Sunday," 你可以 simplify/factor 这个:
如果你把"last Sunday"理解为"the Sunday which has most recently happened:"
=DATE(A2,B2,C2) - WEEKDAY(DATE(A2,B2,C2)) + 1
如果你把"last Sunday"理解为"the Sunday which took place during the previous week:"
=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
带你从上周的周六到本周的周日(我称之为 "this Sunday"),- 6
带你回到上周我称之为 "last Sunday."
看这里:
尝试:
=ARRAYFORMULA(TO_DATE(FILTER(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))),
TEXT(ROW(INDIRECT(VALUE(TODAY()-6)&":"&VALUE(TODAY()))), "ddd")="Sun")))
如果今天是星期天,而您仍然想要最后一个星期天,那么:
=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"))))
使用星期一作为 1 索引,这将 return 前一个星期日或今天(如果是星期日)
=if((7-WEEKDAY(today(),2))>0,today()-(7-(7-WEEKDAY(today(),2))),today()+(7-WEEKDAY(today(),2)))
可以 select 通过在模式存在的三个地方直接更改“-WEEKDAY(today(),2)”之前的数字“7”来 select。