Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a month Function
Hi,
Does anyone know how to work out how many days a month has? Something that can accomodate leap years as well. So, if it's Feb 2005 it's 28 days. If it were Feb 2004 it would be 29 days. -- Many thanks in advance for any assistance |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a month Function
If some date in that month is given in cell A1
=DAY(DATE(YEAR(A1),MONTH(A1)+1,0)) Steve "Marek" wrote in message ... Hi, Does anyone know how to work out how many days a month has? Something that can accomodate leap years as well. So, if it's Feb 2005 it's 28 days. If it were Feb 2004 it would be 29 days. -- Many thanks in advance for any assistance |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a month Function
Thanks - gives me a clue. How could I do this purely from code - I don't
have a cell reference for the date. -- Many thanks in advance for any assistance "Steve Yandl" wrote: If some date in that month is given in cell A1 =DAY(DATE(YEAR(A1),MONTH(A1)+1,0)) Steve "Marek" wrote in message ... Hi, Does anyone know how to work out how many days a month has? Something that can accomodate leap years as well. So, if it's Feb 2005 it's 28 days. If it were Feb 2004 it would be 29 days. -- Many thanks in advance for any assistance |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a month Function
In VB, the last day of any month is day 0 of the following month (i.e.,
First of next month, less one day) NumDaysInMyDate = Day(DateSerial(Year(MyDate), Month(MyDate)+1, 0)) The DateSerial(year,month,day) function calculates "Day 0" of the month following MyDate. Equivalent to MyDate's EOM. The Day(datevalue) function returns the number (1-31) of that day (i.e., the number of days within the month of MyDate) Leap years are covered. HTH, -- George Nicholson Remove 'Junk' from return address. "Marek" wrote in message ... Hi, Does anyone know how to work out how many days a month has? Something that can accomodate leap years as well. So, if it's Feb 2005 it's 28 days. If it were Feb 2004 it would be 29 days. -- Many thanks in advance for any assistance |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a month Function
One way:
Public Function DaysInMonth(vDate As Variant) As Variant Dim nDaysInMonth As Long On Error GoTo ErrHandler nDaysInMonth = Day(DateSerial(Year(vDate), Month(vDate) + 1, 0)) DaysInMonth = nDaysInMonth Continue: On Error GoTo 0 Exit Function ErrHandler: DaysInMonth = CVErr(xlErrValue) Resume Continue End Function In article , "Marek" wrote: Thanks - gives me a clue. How could I do this purely from code - I don't have a cell reference for the date. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Days in a month Function
that works a treat - many thanks for that. It never ceases to amaze me the
input on these forums and the speed folk can respond nowadays. "George Nicholson" wrote: In VB, the last day of any month is day 0 of the following month (i.e., First of next month, less one day) NumDaysInMyDate = Day(DateSerial(Year(MyDate), Month(MyDate)+1, 0)) The DateSerial(year,month,day) function calculates "Day 0" of the month following MyDate. Equivalent to MyDate's EOM. The Day(datevalue) function returns the number (1-31) of that day (i.e., the number of days within the month of MyDate) Leap years are covered. HTH, -- George Nicholson Remove 'Junk' from return address. "Marek" wrote in message ... Hi, Does anyone know how to work out how many days a month has? Something that can accomodate leap years as well. So, if it's Feb 2005 it's 28 days. If it were Feb 2004 it would be 29 days. -- Many thanks in advance for any assistance |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
excel to make the days cary over month to month automaticly | New Users to Excel | |||
Number of days in month counted from shortened name of month & yea | Excel Worksheet Functions | |||
Days per month for calculating storage days | Excel Worksheet Functions | |||
function to fill all days of month to end of month | Excel Worksheet Functions | |||
function to fill all days of month to end of month | Excel Worksheet Functions |