Skip to content

[ lubridate ](../index.html) 1.9.2

  * [ Get started ](../articles/lubridate.html)
  * [ Reference ](../reference/index.html)
  * News 

######  Releases

[ Version 1.7.0 ](https://www.tidyverse.org/blog/2017/11/lubridate-1.7.0/) [
Version 1.6.0 ](https://www.rstudio.com/blog/lubridate-1-6-0/) [ Version 1.2.0
](https://www.rstudio.com/blog/lubridate-1-2-0-now-on-cran/)

[ Changelog ](../news/index.html)

  * [ ](https://github.com/tidyverse/lubridate/)

![](../logo.png)

#  Do more with dates and times in R

Source: [ ` vignettes/lubridate.Rmd `
](https://github.com/tidyverse/lubridate/blob/HEAD/vignettes/lubridate.Rmd)

` lubridate.Rmd `

(This vignette is an updated version of the blog post first published at [
r-statistics ](https://www.r-statistics.com/2012/03/do-more-with-dates-and-
times-in-r-with-lubridate-1-1-0/) _

Lubridate is an R package that makes it easier to work with dates and times.
Below is a concise tour of some of the things lubridate can do for you.
Lubridate was created by Garrett Grolemund and Hadley Wickham, and is now
maintained by Vitalie Spinu.

##  Parsing dates and times

Getting R to agree that your data contains the dates and times you think it
does can be tricky. Lubridate simplifies that. Identify the order in which the
year, month, and day appears in your dates. Now arrange “y”, “m”, and “d” in
the same order. This is the name of the function in lubridate that will parse
your dates. For example,

    
    
    [library](https://rdrr.io/r/base/library.html)([lubridate](https://lubridate.tidyverse.org))
    #> 
    #> Attaching package: 'lubridate'
    #> The following objects are masked from 'package:base':
    #> 
    #>     date, intersect, setdiff, union
    [ymd](../reference/ymd.html)("20110604")
    #> [1] "2011-06-04"
    [mdy](../reference/ymd.html)("06-04-2011")
    #> [1] "2011-06-04"
    [dmy](../reference/ymd.html)("04/06/2011")
    #> [1] "2011-06-04"

Lubridate’s parse functions handle a wide variety of formats and separators,
which simplifies the parsing process.

If your date includes time information, add h, m, and/or s to the name of the
function. ` ymd_hms ` is probably the most common date time format. To read
the dates in with a certain time zone, supply the official name of that time
zone in the ` tz ` argument.

    
    
    arrive <- [ymd_hms](../reference/ymd_hms.html)("2011-06-04 12:00:00", tz = "Pacific/Auckland")
    arrive
    #> [1] "2011-06-04 12:00:00 NZST"
    leave <- [ymd_hms](../reference/ymd_hms.html)("2011-08-10 14:00:00", tz = "Pacific/Auckland")
    leave
    #> [1] "2011-08-10 14:00:00 NZST"

##  Setting and Extracting information

Extract information from date times with the functions ` second ` , ` minute `
, ` hour ` , ` day ` , ` wday ` , ` yday ` , ` week ` , ` month ` , ` year ` ,
and ` tz ` . You can also use each of these to set (i.e, change) the given
information. Notice that this will alter the date time. ` wday ` and ` month `
have an optional ` label ` argument, which replaces their numeric output with
the name of the weekday or month.

    
    
    [second](../reference/second.html)(arrive)
    #> [1] 0
    [second](../reference/second.html)(arrive) <- 25
    arrive
    #> [1] "2011-06-04 12:00:25 NZST"
    [second](../reference/second.html)(arrive) <- 0
    
    [wday](../reference/day.html)(arrive)
    #> [1] 7
    [wday](../reference/day.html)(arrive, label = TRUE)
    #> [1] Sat
    #> Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat

##  Time Zones

There are two very useful things to do with dates and time zones. First,
display the same moment in a different time zone. Second, create a new moment
by combining an existing clock time with a new time zone. These are
accomplished by ` with_tz ` and ` force_tz ` .

For example, a while ago I was in Auckland, New Zealand. I arranged to meet
the co-author of lubridate, Hadley, over skype at 9:00 in the morning Auckland
time. What time was that for Hadley who was back in Hou