如何使用Google表格获取与上一年的星期几和星期几相同的日期?

时间:2019-07-18 05:41:43

标签: date google-sheets google-sheets-formula array-formulas week-number

我正在寻找一种使Google表格中的日期与上一年的周号和星期几相同的方法。

例如,

Input   : 12/22/2018 Saturday of week 51.
Output  : 12/23/2017 Saturday of week 51.

但是有一个例外, 像这样

Input   : 12/31/2018 Monday of week 53.
Output  : 01/01/2018 Saturday of week 1.

Input   : 01/01/2017 Monday of week 1.
Output  : 01/03/2016 Sunday of week 2.

也想获得ISOweek。

例如,

Input   : 01/02/2016 Saturday of week 53.
Output  : 01/03/2015 Saturday of week 1.

1 个答案:

答案 0 :(得分:0)

=ARRAYFORMULA(TEXT(IFERROR(VLOOKUP(TEXT(A1, "ddd")&WEEKNUM(A1, 1), {TEXT(ROW(INDIRECT(
  "A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))-14&
 ":A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))+14)), "ddd")&WEEKNUM(ROW(INDIRECT(
  "A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))-14&
 ":A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))+14)), 1), ROW(INDIRECT(
  "A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))-14&
 ":A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))+14))}, 2, 0), 
 VLOOKUP(IF(WEEKNUM(A1, 1)+1=54, 1, WEEKNUM(A1, 1)+1), {WEEKNUM(ROW(INDIRECT(
  "A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))-14&
 ":A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))+14)), 1), ROW(INDIRECT(
  "A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))-14&
 ":A"&DATEVALUE(DATE(YEAR(A1)-1, MONTH(A1), DAY(A1)))+14))}, 2, 0)), "yyyy/mm/dd"))

0