I have two dates let´s say 14.01.2013
and 26.03.2014
.
I would like to get the difference between those two dates in terms of weeks(?), months(in the example 14), quarters(4) and years(1).
Do you know the best way to get this?
Select a blank cell which will place the calculated result, enter this formula =DATEDIF(A2,B2,"Y") & " Years, " & DATEDIF(A2,B2,"YM") & " Months, " & DATEDIF(A2,B2,"MD") & " Days", press Enter key to get the result.
To calculate the number of weeks between two dates, start by counting the number of days between the start and end date. Then, divide that number by 7 days per week. How many days are between two dates?
what about this:
# get difference between dates `"01.12.2013"` and `"31.12.2013"` # weeks difftime(strptime("26.03.2014", format = "%d.%m.%Y"), strptime("14.01.2013", format = "%d.%m.%Y"),units="weeks") Time difference of 62.28571 weeks # months (as.yearmon(strptime("26.03.2014", format = "%d.%m.%Y"))- as.yearmon(strptime("14.01.2013", format = "%d.%m.%Y")))*12 [1] 14 # quarters (as.yearqtr(strptime("26.03.2014", format = "%d.%m.%Y"))- as.yearqtr(strptime("14.01.2013", format = "%d.%m.%Y")))*4 [1] 4 # years year(strptime("26.03.2014", format = "%d.%m.%Y"))- year(strptime("14.01.2013", format = "%d.%m.%Y")) [1] 1
as.yearmon()
and as.yearqtr()
are in package zoo
. year()
is in package lubridate
. What do you think?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With