Search code examples
arraysgoogle-sheetsdatediffarray-formulas

Dynamically create array using formula


I need to dynamically create an array containing all months between two dates, using =DATEDIF() in Google Spreadsheets. For instance, =DATEDIF(B2,B3,"M") returns 11, so I need an array containing all the months between October 2015 and September 2016.

Is it possible to accomplish this using formulas? Many thanks!


Solution

  • try this:

    =ArrayFormula(TEXT(EOMONTH(A1,row(OFFSET(A1,,,DATEDIF(A1,A2,"m")))-1),"m"))
    

    assuming A1 = date1 (October 2015), A2 = Date2 (September 2016) in date format. A1 in offset part is the refference on first cell.

    change second "m" in formula to get formats:

    • "m" = {1,2,3,4...}
    • "mm" = {01,02,03...}
    • "yyyymm" = {201510, 201511, 201512, 201601...}

    example file