## Calculate last date of a given month

The formula in cell C3 calculates the last date for the given month and year in cell B3.

### Explaining formula in cell C3

The DATE function returns an Excel date based on a year, month and day number. DATE(*year*, *month*, *day*) but first we need to extract the argument numbers needed.

The YEAR function calculates the year of an Excel date value. YEAR(B3) becomes YEAR(6026) and returns 1916.

The MONTH function returns the number of the month of an Excel date value. However, we also add 1 to that number. This move takes us to the next month.

MONTH(B3)+1 becomes MONTH(6026)+1 becomes 6 + 1 and returns 7.

The third argument will always be 1. This makes sure that the DATE function always returns the first date of the next month. The DATE function now looks like this:

DATE(*1906*, *7*, *1*) and returns 7/1/1906.

*But wait, we needed the last date in the previous month?* Yes, but subtract the Excel date with 1 and you get the last date of the previous month. This takes care of weird things like leap years that might cause trouble to the calculations.

7/1/1906 -1 is 6/30/1906.

Question: I am trying to create an excel spreadsheet that has a date range. Example: Cell A1 1/4/2009-1/10/2009 Cell B1 [โฆ]

Find latest date based on a condition

Table of contents Lookup a value and find max date How to enter an array formula Explaining array formula Download [โฆ]

Formula for matching a date within a date range

Table of contents Match a date when a date range is entered in a single cell Match a date when [โฆ]

Count dates inside a date range

How do I automatically count dates in a specific date range? Array formula in cell D3: =SUM(IF(($A$2:$A$10<$D$2)*($A$2:$A$10>$D$1), 1, 0)) + [โฆ]

Use MEDIAN function to calculate overlapping ranges

I found an old post that I think is interesting to write about today. Think of two overlapping ranges, it may be dates, [โฆ]

Count specific WEEKDAYS between two dates

If you want to count specific weekdays like for example Mondays and Wednesdays you need a more complicated array formula. [โฆ]

7 days (weekly) date ranges using a formula

Shannon asks:I need a formula that if I enter a start date in field B1 such as 6/8/11 it will [โฆ]

Question: I have a column "B" with a last name.. I have another columb with a date in it "C"... [โฆ]

The DATEDIF function in cell E3 allows you to calculate days between two dates. Related articles Use MEDIAN function to [โฆ]

How to count workdays between two dates

Excel contains a great function that easily counts the number of workdays between two dates, it even allows you to [โฆ]

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form