Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default # of days in that month for a selected date

What is the formula to return the # of days in that month for a randomly
selected date? Thanks for the help.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default # of days in that month for a selected date

As far as I know there is not a direct formula for this, however, by
combining several formulas it is possible to solve.

Let's say the "randomly selected date" is in cell A1, then put this formula
in A2 to display the number of days in that month:
=EOMONTH(A1;0)-DATE(YEAR(A1);MONTH(A1);1)+1

This is what happens:
EOMONTH(A1;0) returns the serial number of the last day in the moth of the
date in A1
YEAR(A1) returns the year of the date in A1
MONTH(A1) returns tha month of the date in A1
DATE(YEAR(A1);MONTH(A1);1) returns the date with same year as A1, same month
as A1, day 1 of that month
if you subtract the last day of the month with the first day of the month
and add 1 then you get the total number of days in that month

NOTE: Excel will most probably automatically change the Number format of
cell A2 to date-time in this case, which does not give you any useful output.
Select A2, choose format cells and change number to "General" (or to "Number"
with "decimal places" = 0)

"Narnimar" wrote:

What is the formula to return the # of days in that month for a randomly
selected date? Thanks for the help.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,646
Default # of days in that month for a selected date

=DAY(DATE(YEAR(A1),MONTH(A1)+1,0))
seems to me a little bit simpler and doesn't require Analysis Toolpak
(EOMONTH does). You have to format the result cell as General in this case,
too.

Regards,
Stefi

€˛Valdus€¯ ezt Ć*rta:

As far as I know there is not a direct formula for this, however, by
combining several formulas it is possible to solve.

Let's say the "randomly selected date" is in cell A1, then put this formula
in A2 to display the number of days in that month:
=EOMONTH(A1;0)-DATE(YEAR(A1);MONTH(A1);1)+1

This is what happens:
EOMONTH(A1;0) returns the serial number of the last day in the moth of the
date in A1
YEAR(A1) returns the year of the date in A1
MONTH(A1) returns tha month of the date in A1
DATE(YEAR(A1);MONTH(A1);1) returns the date with same year as A1, same month
as A1, day 1 of that month
if you subtract the last day of the month with the first day of the month
and add 1 then you get the total number of days in that month

NOTE: Excel will most probably automatically change the Number format of
cell A2 to date-time in this case, which does not give you any useful output.
Select A2, choose format cells and change number to "General" (or to "Number"
with "decimal places" = 0)

"Narnimar" wrote:

What is the formula to return the # of days in that month for a randomly
selected date? Thanks for the help.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 293
Default # of days in that month for a selected date

Hi Narnimar,

Here's another way:
=DATE(YEAR(A1),MONTH(A1)+1,0)-DATE(YEAR(A1),MONTH(A1),0)

--
Cheers
macropod
[MVP - Microsoft Word]


"Narnimar" wrote in message ...
What is the formula to return the # of days in that month for a randomly
selected date? Thanks for the help.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default # of days in that month for a selected date


I copied it but Formula throws an error to me. Thanks to you to verify and
reply.

"Valdus" wrote:

As far as I know there is not a direct formula for this, however, by
combining several formulas it is possible to solve.

Let's say the "randomly selected date" is in cell A1, then put this formula
in A2 to display the number of days in that month:
=EOMONTH(A1;0)-DATE(YEAR(A1);MONTH(A1);1)+1

This is what happens:
EOMONTH(A1;0) returns the serial number of the last day in the moth of the
date in A1
YEAR(A1) returns the year of the date in A1
MONTH(A1) returns tha month of the date in A1
DATE(YEAR(A1);MONTH(A1);1) returns the date with same year as A1, same month
as A1, day 1 of that month
if you subtract the last day of the month with the first day of the month
and add 1 then you get the total number of days in that month

NOTE: Excel will most probably automatically change the Number format of
cell A2 to date-time in this case, which does not give you any useful output.
Select A2, choose format cells and change number to "General" (or to "Number"
with "decimal places" = 0)

"Narnimar" wrote:

What is the formula to return the # of days in that month for a randomly
selected date? Thanks for the help.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default # of days in that month for a selected date

Maybe a bit shorter

=32-DAY(A1-DAY(A1)+32)

Format as general

Mike

"Narnimar" wrote:

What is the formula to return the # of days in that month for a randomly
selected date? Thanks for the help.

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default # of days in that month for a selected date

As Stefi mentioned EOMONTH needs Analysis Toolpak to be installed.
This is a very useful toolpak to have installed, but I think you have
received a lot of help from the other users where you don't need it for this
issue.

"Narnimar" wrote:


I copied it but Formula throws an error to me. Thanks to you to verify and
reply.

"Valdus" wrote:

As far as I know there is not a direct formula for this, however, by
combining several formulas it is possible to solve.

Let's say the "randomly selected date" is in cell A1, then put this formula
in A2 to display the number of days in that month:
=EOMONTH(A1;0)-DATE(YEAR(A1);MONTH(A1);1)+1

This is what happens:
EOMONTH(A1;0) returns the serial number of the last day in the moth of the
date in A1
YEAR(A1) returns the year of the date in A1
MONTH(A1) returns tha month of the date in A1
DATE(YEAR(A1);MONTH(A1);1) returns the date with same year as A1, same month
as A1, day 1 of that month
if you subtract the last day of the month with the first day of the month
and add 1 then you get the total number of days in that month

NOTE: Excel will most probably automatically change the Number format of
cell A2 to date-time in this case, which does not give you any useful output.
Select A2, choose format cells and change number to "General" (or to "Number"
with "decimal places" = 0)

"Narnimar" wrote:

What is the formula to return the # of days in that month for a randomly
selected date? Thanks for the help.

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 747
Default # of days in that month for a selected date

Try this

=DAY(DATE(YEAR(A1),MONTH(A1)+1,0))



On Sep 19, 2:16*am, Narnimar
wrote:
What is the formula to return the # of days in that month *for a randomly
selected date? Thanks for the help.


  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default # of days in that month for a selected date

This is very cute. Thanks a lot.

"Mike H" wrote:

Maybe a bit shorter

=32-DAY(A1-DAY(A1)+32)

Format as general

Mike

"Narnimar" wrote:

What is the formula to return the # of days in that month for a randomly
selected date? Thanks for the help.

  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default # of days in that month for a selected date

Well I've rarely heard of a formula described as 'Cute' but there we are!!.
Thanks for the feedback.

Mike

"Narnimar" wrote:

This is very cute. Thanks a lot.

"Mike H" wrote:

Maybe a bit shorter

=32-DAY(A1-DAY(A1)+32)

Format as general

Mike

"Narnimar" wrote:

What is the formula to return the # of days in that month for a randomly
selected date? Thanks for the help.

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
How to calculate a date: first day of the month after 60 days Claudia Excel Discussion (Misc queries) 12 June 28th 07 05:10 AM
Date glitch? First 12 days of month format differently than the r yakalo Excel Discussion (Misc queries) 3 April 9th 07 01:18 AM
Fomula for number of days on each month from a date range [email protected] Excel Discussion (Misc queries) 3 November 9th 06 03:08 AM


All times are GMT +1. The time now is 06:36 PM.

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"