How to calculate number of days in Excel - excel

I have a date format like 2020-01-17.I would like to calculate number of days till today date. I'm trying it's like
=today() - B2
However it's not working.
Edit
I changed the format to 01/17/2020 and did
=today() - B2
The result comes as 3/23/1900.
This is wrong and I would like to see in number of days.

very simple
Check Out Image enter image description here

I think there are 2 issues that you're seeing here.
The result comes as 3/23/1900.
The reason you're seeing this result as 3/23/1900 is probably because of the format of the cell. Change cell format to number and you should see your result as a number.
Or you can also use the formula with a VALUE formula like so =VALUE(today() - B2)
I would like to calculate number of days till today date
You can always use a simple subtraction of the two dates.
You can also use the DATEDIF function and extract the difference between dates in Years, Months, Days and more. Example: =DATEDIF(today(), B2,"D")
Here is the documentation for this DATEDIF function.
Note: Below is the warning from Microsoft
Warning: Excel provides the DATEDIF function in order to support older workbooks from Lotus 1-2-3. The DATEDIF function may calculate incorrect results under certain scenarios. Please see the known issues section of this article for further details

You can you use the datedif fx link: https://exceljet.net/excel-functions/excel-datedif-function
=DATEDIF(B2,TODAY(),"D")

Related

TODAY() function not working in Microsoft Excel

I want to calculate the number of days that have elapsed from the start date. For that I am using the function =TODAY()-C3. You can see in the image that C3 contains the start date. But the answer is coming "03-Jan-00". If I just write =TODAY() or =TODAY()+5 it is working. I am attaching the screenshot and a google drive link where you can see the screen recording of the problem for a better understanding.
https://drive.google.com/file/d/1lQ7djK1BRICjFfAaAG0T08snuRZhcU-k/view?usp=share_link
Works as shown:
Just note that cell c1 is formatted as number.
The reason that you need to format as a number is because that is the result you expect. ie the difference between two dates is a number of days, not a day with month and year.

Dates are not recognized

I have written a conditional formula to recognize two dates (greater than and last than). However, there are a few dates that are returning 'false'. All of the columns are formatted as a date. Can someone please help?
This is not a direct answer to the question asked, but as Scott said, the formula you use is much more complex than necessary. If you need to return a number for a date that falls within a period and the periods do not overlap, the following formula can be used:
=SUMPRODUCT((AQ3>=$DF$3:$DF$15)*(AQ3<=$DF$3:$DF$15),$DH$3:$DH$15)
If you need to process text values, it is more complicated. For example, if 'expired' is the only value (also for dates that do not fit into any period), then we can add the IF function to the previous formula:
=IF(SUMPRODUCT((AQ3>=$DF$3:$DF$15)*(AQ3<=$DF$3:$DF$15),$DH$3:$DH$15)>0,SUMPRODUCT((AQ3>=$DF$3:$DF$15)*(AQ3<=$DF$3:$DF$15),$DH$3:$DH$15),"expired")

Counting Number of Months between Two Dates in Excel

So I am attempting to simply count the number of months bewtween an earlier date and today, which will be in the B:B column; once the number of months have been counted, the result is then multiplied by 28, then added back to the original date. Note the requirement: Result >= Today, so basically if the result is less than today it needs to add another 28 days. The current formula I made only works if the dates are in the current year (and I am not 100% sure if this formula works, it appears to so far though.)
Here is my defunct formula, but maybe someone can get a general idea from my above comments and the below formula of what I am attempting to achieve here:
=IF(B89="","",IF(I89="X","LEG",IFERROR(IF((MONTH(TODAY()-B89)*28)+B89<TODAY(),(MONTH(TODAY()-B89)*28)+B89+28,(MONTH(TODAY()-B89)*28)+B89),"Future")))
Thank you in advance for your assistance!
Note: I just want to point out that the reference to I89 is insignificant in the above. I just didn't want to remove it in case I deleted the wrong parenthesis or some other typo, so I decided to leave in there. So basically you would not need to necessarily worry about the first two "IF" statements, nor the IFERROR, unless you just wanted to!
2ND EDIT: Okay I decided to strip down formula, original post's formula is above, the stripped version below:
IF((MONTH(TODAY()-B89)*28)+B89<TODAY(),(MONTH(TODAY()-B89)*28)+B89+28,(MONTH(TODAY()-B89)*28)+B89)
You should not use MONTH() for this purpose as this will lead to wrong results in some cases, and certainly when the B89 date is in another year.
Instead see how many days you are past the last multiple of 28 days since B89, and go back to that date (by subtracting), and then add another 28 to it:
=TODAY() + 28 - MOD((TODAY()-B89), 28)
The earliest date this can give is the date of tomorrow. If today should be an acceptable outcome of the formula, then replace TODAY() with TODAY()-1, which results in this formula:
=TODAY() + 27 - MOD((TODAY()-1-B89), 28)
How about something like this:
=IF(B89="","",IF(I89="X","LEG",IF(IF(B89<=TODAY(),B89+28*IF(AND(B89<TODAY(),TEXT(B89,"mmyy")=TEXT(TODAY(),"mmyy")),"1",(TEXT(TODAY(),"yy")*12+MONTH(TODAY()))-(TEXT(B89,"yy")*12+MONTH(B89))),"Future")<TODAY(),TODAY(),IF(B89<=TODAY(),B89+28*IF(AND(B89<TODAY(),TEXT(B89,"mmyy")=TEXT(TODAY(),"mmyy")),"1",(TEXT(TODAY(),"yy")*12+MONTH(TODAY()))-(TEXT(B89,"yy")*12+MONTH(B89)))))))
Got a little long now, but you have a lot of criteria :)

Excel date difference #Value error

I have two columns:
C2=4/27/15 11:00:26 AM
D2=4/27/15 11:01:46 AM
I'm trying to calculate the time difference in seconds using the formula
=(D2-C2)*24*60*60
But I'm getting #Value error.
Generally a #VALUE error means you are trying to do math on a text value. One of your dates is probably in text format.
Try retyping your dates and see if that makes your formula work.
If you need to have the actual seconds in a number you can use elsewhere then your formula should work, if the dates are in the correct format.
Here are the specific ways to get the time difference between two dates in two different cells - notice the cell format is important:
https://support.office.com/en-ca/article/Calculate-the-difference-between-two-times-e1c78778-749b-49a3-b13e-737715505ff6
And the DATEDIF function gives you the difference in days/months/years
=DATEDIF(C2,D2,"M")
You should use the INT function
=INT((D2-C2)*86400)
And as #Tember mentioned, cell formats are important..

date conversion formula in excel

I have some dated in this format "09-MAY-13 06.42.46.097127000 PM" and need to convert to this format "2013-05-09T18:42:47.132Z". my goal is to find out which happend earlier. I am not sure how to format these dates.
2013-05-09T18:42:47.132Z 09-MAY-13 06.42.46.097127000 PM
2013-05-08T20:56:55.821Z 06-MAY-13 03.22.09.129443000 PM
2013-05-08T20:51:45.287Z 06-MAY-13 03.03.22.975700000 PM
2013-05-08T20:55:34.719Z 06-MAY-13 10.40.55.924181000 PM
How I can do that??
I originally posted an answer which converted one of your formats to the other. I now see that you need to compare them, so you can convert this format in A2 to date/number values ....
09-MAY-13 06.42.46.097127000 PM
.....with this formula
=SUBSTITUTE(SUBSTITUTE(A2,".",":",1),".",":",1)+0
and this format in A3
2013-05-09T18:42:46.097z
....with this formula
=SUBSTITUTE(SUBSTITUTE(A3,"T"," "),"z","")+0
You can format the results how you like, leave as numbers or format as m/d/yyyy hh:mm:ss.000 or similar. you can now compare easily with a formula like
=B2>B3
or get the smaller or larger with MIN or MAX
If have a value of your original style in cell A1, place the following formula in a different cell:
=DATE((2000+MID(A1,8,2)),MATCH(MID(A1,4,3),{"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"},0),LEFT(A1,2))+TIME(MID(A1,11,2)+IF(RIGHT(A1,2)="PM",12,0),MID(A1,14,2),MID(A1,17,12))
Then, in that target cell, apply the following format:
yyyy-mm-ddThh:mm:ssZ
Please note the following:
This assumes that all of your months are 3 characters (JAN, FEB, MAR). Since your example was "MAY" (already 3 characters), I don't know with certainty how your other months appear. Longer month names complicate the formula a bit. I can help with this if you need it and don't know how to do it.
I couldn't find a way to force Excel to display fractional seconds in the context of such complex date/time formatting, even though your example showed seconds subdivided to the thousandths. Hopefully this isn't a deal-breaker. If it's necessary to display fractional seconds, you may need to handle this with a separate formula to display the result as text, independent of the formula above, which you can use for your calculations of which date came earlier.
To add to Joe's answer...
To get Excel to compare one column to the other you need to do the same sort of manipulation from the first column as the second.
That would look like
=DATE(LEFT(A1,4),MID(A1,6,2),MID(A1,9,2))+TIME(MID(A1,12,2),MID(A1,15,2),MID(A1,18,5))
Once you have a new column for each of these transformations it should be simple to have Excel compare them.

Resources