Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

I have in A1 = '20-05-2012' B1 = 'NO' and I want in C1 a formula to calculate the number of days between to dates, so:

C#
string today = DateTime.Now;

if(B1='NO')
{
   //Here I want that C1 = '3'
   //and tomorow will C1 = '4' 
   //because the number of days between 20-05-2012 and 23-05-2012 = 3
   //and tomorrow the number of days between 20-05-2012 and 24-05-2012 = 4
}

How I do this in excel?
I hope you understand my question...

Regards,
KZ
Posted
Updated 23-May-12 6:36am
v2

 
Share this answer
 
v2
If you want highly efficient algorithms, then you want look at:
http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html[^]
 
Share this answer
 
I already solve it my friend:

=IF(E4="NO";(D4-TODAY())*-1;"OK")

this gives me the number of days between two dates:

D4="23-05-2012"

(D4-TODAY())*-1

But thanks!

KZ
 
Share this answer
 
Comments
Richard MacCutchan 24-May-12 4:31am    
Why do you need to multiply by -1? What is wrong with TODAY()-D4?
Killzone DeathMan 24-May-12 4:37am    
Because ('23-05-2012') - ('24-05-2012') = -1
and (-1)*(-1) = 1
I don't know why the result is -1, but multiply by -1 it works :)
Richard MacCutchan 24-May-12 4:42am    
Like I said, why not just use TODAY()-D4?
Killzone DeathMan 24-May-12 4:49am    
Because...because... come on my friend, it looks more mathematically...
But 'TODAY()-D4' and '(D4-TODAY())*-1' are the same! :)
Richard MacCutchan 24-May-12 4:54am    
They are indeed the same in terms of the result, but why make a formula more complicated than it needs to be? Imaging some intern 5 years from now looking at that formula and wondering why it needs the 'extra' bit of calculation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900