Google-sheets – List of dates of current and previous month in Google Sheets

dategoogle sheets

I want to have the dates of the current month and the previous month automatically get populated. So I'm using =MONTH(NOW()) to get the current month and =MONTH(NOW())-1 to get the previous month. Beneath them I'd like the dates to get listed just for that month. So for example it would look like this:

1

Is this possible?

Best Answer

With the following formula you can construct a month table, containing all days of the month.

Formula

=ARRAYFORMULA(
   DATE(
     YEAR(NOW()),                                                    // first
     A1,                                                             // second
     ROW(                                                            // third
       INDIRECT("A1:A" & DAY(EOMONTH(DATE(YEAR(NOW()), A1, 1), 0)))
     )   
   )
 )

 copy / past
 =ARRAYFORMULA(DATE(YEAR(NOW()),A1,ROW(INDIRECT("A1:A" & DAY(EOMONTH(DATE(YEAR(NOW()), A1, 1), 0))))))

Screenshot

enter image description here

Explained

The DATE formula is used to construct the date out of the three integers it needs. The first is the YEAR, being calculated from the NOW formula. The second argument is the month that you want to calculate the days from. The third argument must be a day number. Because we're using an ARRAYFORMULA, this is fed by a ROW range. The range of the rows, is dependent upon the amount of days per month. This number is calculated as follows:

DAY(                  // days
  EOMONTH(            // days till end of month in date notation
    DATE(
      YEAR(NOW()),    // from year 
      A1,             // from month
      1               // from day    
   )
 )

Example

I've created an example file for you: Days of Month