# Thread: How Many Days (XP)

1. ## How Many Days (XP)

Is there a function that will determine the number of days in the month if you know the month and year ie 02 and 2004.

Thanks,
John

2. ## Re: How Many Days (XP)

With the month in A1 & the year in A2

=DAY(DATE(A2,A1+1,0))

3. ## Re: How Many Days (XP)

If the date is in A1:

<pre>=DAY(DATE(YEAR(A1),MONTH(A1)+1,0))
</pre>

Thank you

5. ## Re: How Many Days (XP)

Assuming your month and year are in A1 as 02/2004, I always use "DAY(EOMONTH(A1,0))"

6. ## Re: How Many Days (XP)

To use the EOMONTH function you must install and load the Analysis ToolPak add-in otherwise you will get a #NAME error.

7. ## Re: How Many Days (XP)

Tony,

Let's take it to the next step via code:

Sub TestDays()
Dim oMo As Integer
Dim oYr As Integer
oMo = "11"
oYr = "2004"
oDays = Day(Date(oYr,oMo +1,0)) 'I receive a compile error on this line
End Sub

I don't understand why I am receiving the compile error.

Thanks,
John

8. ## Re: How Many Days (XP)

DATE is a worksheet function, and its VBA equivalent is DateSerial. The VBA function Date returns the current date - like the worksheet function TODAY.

Isn't is fun? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

9. ## Re: How Many Days (XP)

Hans,

It now makes sense. Back to the <img src=/S/read.gif border=0 alt=read width=19 height=33> to learn a little more about DateSerial.

Thanks,
John

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•