ference/ymd.html)(20120101) + [years](../reference/period.html)(1)
    #> [1] "2013-01-01"

You can use periods and durations to do basic arithmetic with date times. For
example, if I wanted to set up a reoccuring weekly skype meeting with Hadley,
it would occur on:

    
    
    meetings <- meeting + [weeks](../reference/period.html)(0:5)

Hadley travelled to conferences at the same time as Chris. Which of these
meetings would be affected? The last two.

    
    
    meetings [%within%](../reference/within-interval.html) jsm
    #> [1] FALSE FALSE FALSE  TRUE  TRUE  TRUE

How long was my stay in Auckland?

    
    
    auckland / [ddays](../reference/duration.html)(1)
    #> [1] 67.08333
    auckland / [ddays](../reference/duration.html)(2)
    #> [1] 33.54167
    auckland / [dminutes](../reference/duration.html)(1)
    #> [1] 96600

And so on. Alternatively, we can do modulo and integer division. Sometimes
this is more sensible than division - it is not obvious how to express a
remainder as a fraction of a month because the length of a month constantly
changes.

    
    
    auckland [%/%](https://rdrr.io/r/base/Arithmetic.html) [months](https://rdrr.io/r/base/weekday.POSIXt.html)(1)
    #> [1] 2
    auckland [%%](https://rdrr.io/r/base/Arithmetic.html) [months](https://rdrr.io/r/base/weekday.POSIXt.html)(1)
    #> [1] 2011-08-04 12:00:00 NZST--2011-08-10 14:00:00 NZST

Modulo with an timespan returns the remainder as a new (smaller) interval. You
can turn this or any interval into a generalized time span with ` as.period `
.

    
    
    [as.period](../reference/as.period.html)(auckland [%%](https://rdrr.io/r/base/Arithmetic.html) [months](https://rdrr.io/r/base/weekday.POSIXt.html)(1))
    #> [1] "6d 2H 0M 0S"
    [as.period](../reference/as.period.html)(auckland)
    #> [1] "2m 6d 2H 0M 0S"

###  If anyone drove a time machine, they would crash

The length of months and years change so often that doing arithmetic with them
can be unintuitive. Consider a simple operation, ` January 31st + one month `
. Should the answer be

  1. ` February 31st ` (which doesn’t exist) 
  2. ` March 4th ` (31 days after January 31), or 
  3. ` February 28th ` (assuming its not a leap year) 

A basic property of arithmetic is that ` a + b - b = a ` . Only solution 1
obeys this property, but it is an invalid date. I’ve tried to make lubridate
as consistent as possible by invoking the following rule _if adding or
subtracting a month or a year creates an invalid date, lubridate will return
an NA_ . This is new with version 1.3.0, so if you’re an old hand with
lubridate be sure to remember this!

If you thought solution 2 or 3 was more useful, no problem. You can still get
those results with clever arithmetic, or by using the special ` %m+% ` and `
%m-% ` operators. ` %m+% ` and ` %m-% ` automatically roll dates back to the
last day of the month, should that be necessary.

    
    
    jan31 <- [ymd](../reference/ymd.html)("2013-01-31")
    jan31 + [months](https://rdrr.io/r/base/weekday.POSIXt.html)(0:11)
    #>  [1] "2013-01-31" NA           "2013-03-31" NA           "2013-05-31"
    #>  [6] NA           "2013-07-31" "2013-08-31" NA           "2013-10-31"
    #> [11] NA           "2013-12-31"
    [floor_date](../reference/round_date.html)(jan31, "month") + [months](https://rdrr.io/r/base/weekday.POSIXt.html)(0:11) + [days](../reference/period.html)(31)
    #>  [1] "2013-02-01" "2013-03-04" "2013-04-01" "2013-05-02" "2013-06-01"
    #>  [6] "2013-07-02" "2013-08-01" "2013-09-01" "2013-10-02" "2013-11-01"
    #> [11] "2013-12-02" "2014-01-01"
    jan31 [%m+%](../reference/mplus.html) [months](https://rdrr.io/r/base/weekday.POSIXt.html)(0:11)
    #>  [1] "2013-01-31" "2013-02-28" "2013-03-31" "2013-04-30" "2013-05-31"
    #>  [6] "2013-06-30" "2013-07-31" "2013-08-31" "2013-09-30" "2013-10-31"
    #> [11] "2013-11-30" "2013-12-31"

Notice that this will only affect arithmetic with months (and arithmetic with
years if your start date it Feb