`DateDiff`

function.Take a look here:

http://msdn.microsoft.com/en-us/library/ms127413.aspx[^]

http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/f7094472-b473-4a29-8a90-d32056d05bef[^]

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

You need

Take a look here:

http://msdn.microsoft.com/en-us/library/ms127413.aspx[^]

http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/f7094472-b473-4a29-8a90-d32056d05bef[^]

`DateDiff`

function.Take a look here:

http://msdn.microsoft.com/en-us/library/ms127413.aspx[^]

http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/f7094472-b473-4a29-8a90-d32056d05bef[^]

Permalink

Share this answer

v2

If you want highly efficient algorithms, then you want look at:

http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html[^]

http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html[^]

Permalink

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

=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

Permalink

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 :)

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! :)

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.

Killzone DeathMan
24-May-12 4:58am

ok ok I understand... I was just joking...

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