#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 18
Default Date/Time

Trying to determine if the date and the time in a cell are the last
day of the month, and if that's the case I want to perform a certain
operation.

Here's what I have so far:

=IF(NOT(DATE(YEAR(A1),MONTH(A1)+1,0)),1,0)

A1 is 2/29/08

My formula returns 0, I would expect this to return a 1 as 2/29/08 IS
the last day of February...
Any ideas why this might not be working?

Thanks

Chris
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,718
Default Date/Time

=--(EOMONTH(A1,0)=A1)


"cmatera" wrote:

Trying to determine if the date and the time in a cell are the last
day of the month, and if that's the case I want to perform a certain
operation.

Here's what I have so far:

=IF(NOT(DATE(YEAR(A1),MONTH(A1)+1,0)),1,0)

A1 is 2/29/08

My formula returns 0, I would expect this to return a 1 as 2/29/08 IS
the last day of February...
Any ideas why this might not be working?

Thanks

Chris

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default Date/Time

The resaon your formula doesn't work is because NOT evaluates to FALSE.

Try one of these:

This one requires the Analysis ToolPak add-in be installed (if using Excel
versions prior to Excel 2007):

=--(DAY(A1)=DAY(EOMONTH(A1,0)))

This one works in all versions of Excel (ATP not required):

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


--
Biff
Microsoft Excel MVP


"cmatera" wrote in message
...
Trying to determine if the date and the time in a cell are the last
day of the month, and if that's the case I want to perform a certain
operation.

Here's what I have so far:

=IF(NOT(DATE(YEAR(A1),MONTH(A1)+1,0)),1,0)

A1 is 2/29/08

My formula returns 0, I would expect this to return a 1 as 2/29/08 IS
the last day of February...
Any ideas why this might not be working?

Thanks

Chris



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default Date/Time

Come to think of it, you don't need the DAY functions:

=--(A1=EOMONTH(A1,0))

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



--
Biff
Microsoft Excel MVP


"T. Valko" wrote in message
...
The resaon your formula doesn't work is because NOT evaluates to FALSE.

Try one of these:

This one requires the Analysis ToolPak add-in be installed (if using Excel
versions prior to Excel 2007):

=--(DAY(A1)=DAY(EOMONTH(A1,0)))

This one works in all versions of Excel (ATP not required):

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


--
Biff
Microsoft Excel MVP


"cmatera" wrote in message
...
Trying to determine if the date and the time in a cell are the last
day of the month, and if that's the case I want to perform a certain
operation.

Here's what I have so far:

=IF(NOT(DATE(YEAR(A1),MONTH(A1)+1,0)),1,0)

A1 is 2/29/08

My formula returns 0, I would expect this to return a 1 as 2/29/08 IS
the last day of February...
Any ideas why this might not be working?

Thanks

Chris





  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Date/Time

Try this...

=IF(DAY(A1+1)=1,1,0)

where 1 is returned if A1 contains a date that is the last day of its month
and 0 otherwise. I'm assuming you will want to replace the 1 and 0 with
something else (text, formula, whatever). If, however, you really want the
output to be 1 or 0, then you can use this instead...

=--(DAY(A1+1)=1)

Rick


"cmatera" wrote in message
...
Trying to determine if the date and the time in a cell are the last
day of the month, and if that's the case I want to perform a certain
operation.

Here's what I have so far:

=IF(NOT(DATE(YEAR(A1),MONTH(A1)+1,0)),1,0)

A1 is 2/29/08

My formula returns 0, I would expect this to return a 1 as 2/29/08 IS
the last day of February...
Any ideas why this might not be working?

Thanks

Chris




  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default Date/Time

Geeez, how easy was that? <g

Nice one!

--
Biff
Microsoft Excel MVP


"Rick Rothstein (MVP - VB)" wrote in
message ...
Try this...

=IF(DAY(A1+1)=1,1,0)

where 1 is returned if A1 contains a date that is the last day of its
month and 0 otherwise. I'm assuming you will want to replace the 1 and 0
with something else (text, formula, whatever). If, however, you really
want the output to be 1 or 0, then you can use this instead...

=--(DAY(A1+1)=1)

Rick


"cmatera" wrote in message
...
Trying to determine if the date and the time in a cell are the last
day of the month, and if that's the case I want to perform a certain
operation.

Here's what I have so far:

=IF(NOT(DATE(YEAR(A1),MONTH(A1)+1,0)),1,0)

A1 is 2/29/08

My formula returns 0, I would expect this to return a 1 as 2/29/08 IS
the last day of February...
Any ideas why this might not be working?

Thanks

Chris




  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Date/Time

Thanks, but actually the basic idea is not original with me... I once saw a
similar test implemented in VB code in a newsgroup posting and it stuck with
me. By the way, I had the same reaction you did when I first saw it too<g.
I am not 100% sure, but I think Dave Peterson posted the original VB coded
version that I am remembering... adapting it for worksheet formula use was
simple.

Rick


"T. Valko" wrote in message
...
Geeez, how easy was that? <g

Nice one!

--
Biff
Microsoft Excel MVP


"Rick Rothstein (MVP - VB)" wrote in
message ...
Try this...

=IF(DAY(A1+1)=1,1,0)

where 1 is returned if A1 contains a date that is the last day of its
month and 0 otherwise. I'm assuming you will want to replace the 1 and 0
with something else (text, formula, whatever). If, however, you really
want the output to be 1 or 0, then you can use this instead...

=--(DAY(A1+1)=1)

Rick


"cmatera" wrote in message
...
Trying to determine if the date and the time in a cell are the last
day of the month, and if that's the case I want to perform a certain
operation.

Here's what I have so far:

=IF(NOT(DATE(YEAR(A1),MONTH(A1)+1,0)),1,0)

A1 is 2/29/08

My formula returns 0, I would expect this to return a 1 as 2/29/08 IS
the last day of February...
Any ideas why this might not be working?

Thanks

Chris





  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,651
Default Date/Time

Go through your formula a stage at a time.

For any date in February 2008 in A1, =DATE(YEAR(A1),MONTH(A1)+1,0) will
return 29th Feb.
=DATE(YEAR(A1),MONTH(A1)+1,1) would return the first day of the fiollowing
month, hence 1st March.
=DATE(YEAR(A1),MONTH(A1)+1,0) is one day before that, which is 29th
February.

All that is fairly academic, because *any* non-zero number is treated as
boolean TRUE, so when you feed that into your NOT function you get FALSE.

You have then fed that FALSE in as the first argument of your IF statement,
and the result you have asked for when the condition is FALSE is zero.

That's why it's not working as you had hoped. Other contributors have
suggested various ways of asking the right question of Excel, and thus
getting the answer you were looking for.
--
David Biddulph

"cmatera" wrote in message
...
Trying to determine if the date and the time in a cell are the last
day of the month, and if that's the case I want to perform a certain
operation.

Here's what I have so far:

=IF(NOT(DATE(YEAR(A1),MONTH(A1)+1,0)),1,0)

A1 is 2/29/08

My formula returns 0, I would expect this to return a 1 as 2/29/08 IS
the last day of February...
Any ideas why this might not be working?

Thanks

Chris



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
Calculating days & time left from start date/time to end date/time marie Excel Worksheet Functions 7 December 7th 05 02:36 PM
Combined date time cell to separate date & time components Mark Ada Excel Discussion (Misc queries) 1 December 2nd 04 02:48 AM
Combined date time cell to separate date & time components Mark Ada Excel Discussion (Misc queries) 1 December 2nd 04 12:07 AM
Combined date time cell to separate date & time components Mark Ada Excel Discussion (Misc queries) 1 December 2nd 04 12:07 AM
Combined date time cell to separate date & time components Mark Ada Excel Worksheet Functions 1 December 2nd 04 12:04 AM


All times are GMT +1. The time now is 03:07 AM.

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

About Us

"It's about Microsoft Excel"