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
How calculate days and month between two dates?
-
- BronzeLounger
- Posts: 1211
- Joined: 01 May 2016, 09:58
-
- 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?
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)"
=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
Hans
-
- BronzeLounger
- Posts: 1211
- Joined: 01 May 2016, 09:58
Re: How calculate days and month between two dates?
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
2- in case I have an older date I get #num how to replace this with something meaning full.
Regards
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
2- in case I have an older date I get #num how to replace this with something meaning full.
Regards
You do not have the required permissions to view the files attached to this post.
-
- 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?
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"))
2) You might use
=IFERROR(DATEDIF(TODAY(),I12,"m"),"-")
or
=IF(I12>=TODAY(),DATEDIF(TODAY(),I12,"m"),-DATEDIF(I12,TODAY(),"m"))
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1211
- Joined: 01 May 2016, 09:58
Re: How calculate days and month between two dates?
thanks a lot that is working very good,