Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel to make the days cary over month to month automaticly GARY New Users to Excel 1 April 19th 08 06:05 PM
Number of days in month counted from shortened name of month & yea Tumar Excel Worksheet Functions 6 September 18th 07 03:36 PM
Days per month for calculating storage days Bart Excel Worksheet Functions 3 January 31st 07 06:40 PM
function to fill all days of month to end of month Monique Excel Worksheet Functions 11 May 1st 06 07:39 PM
function to fill all days of month to end of month YaHootie Excel Worksheet Functions 10 May 1st 06 06:01 AM


All times are GMT +1. The time now is 10:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"