How calculate days and month between two dates?

siamandm
BronzeLounger
Posts: 1211
Joined: 01 May 2016, 09:58

How calculate days and month between two dates?

Post by siamandm »

Hello All
i would like to calculate the number of days between two dates as below :

1/10/2020 today() = let's say today is 5/11/2020 I would like to write a function to give me a result in a cell = 1 month and 5 days

thanks in advance.

Regards

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How calculate days and month between two dates?

Post by HansV »

Wouldn't that be 1 month and 4 days? If so, let's say you have a date in cell D1.

=DATEDIF(D1,TODAY(),"m")&" month(s) and "&DATEDIF(D1,TODAY(),"md")&" day(s)"

If you prefer 1 month and 5 days:

=DATEDIF(D1,TODAY(),"m")&" month(s) and "&DATEDIF(D1,TODAY(),"md")+1&" day(s)"
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1211
Joined: 01 May 2016, 09:58

Re: How calculate days and month between two dates?

Post by siamandm »

thanks a lot, dear Hans, the correct calculation is the first line isn't it ?

i have tried my self this function but i have two questions please,
1- in the screenshot below I'm expecting to have at least 4 months, not 3 months
Screenshot 2020-11-06 104736.jpg

2- in case I have an older date I get #num how to replace this with something meaning full.
Screenshot 2020-11-06 104835.jpg
Regards
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78391
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How calculate days and month between two dates?

Post by HansV »

1) Today is the 6th of November. The 3rd of March next year is less than 4 months from now, so DATEDIF returns 3. If you change the date in I12 to 7-Mar-21, DATEDIF will return 4.

2) You might use

=IFERROR(DATEDIF(TODAY(),I12,"m"),"-")

or

=IF(I12>=TODAY(),DATEDIF(TODAY(),I12,"m"),-DATEDIF(I12,TODAY(),"m"))
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1211
Joined: 01 May 2016, 09:58

Re: How calculate days and month between two dates?

Post by siamandm »

thanks a lot that is working very good,