Package: lubridate 1.9.4

lubridate: Make Dealing with Dates a Little Easier
Functions to work with date-times and time-spans: fast and user friendly parsing of date-time data, extraction and updating of components of a date-time (years, months, days, hours, minutes, and seconds), algebraic manipulation on date-time and time-span objects. The 'lubridate' package has a consistent and memorable syntax that makes working with dates easy and fun.
Authors:
lubridate_1.9.4.tar.gz
lubridate_1.9.4.zip(r-4.5)lubridate_1.9.4.zip(r-4.4)lubridate_1.9.4.zip(r-4.3)
lubridate_1.9.4.tgz(r-4.5-x86_64)lubridate_1.9.4.tgz(r-4.5-arm64)lubridate_1.9.4.tgz(r-4.4-x86_64)lubridate_1.9.4.tgz(r-4.4-arm64)lubridate_1.9.4.tgz(r-4.3-x86_64)lubridate_1.9.4.tgz(r-4.3-arm64)
lubridate_1.9.4.tar.gz(r-4.5-noble)lubridate_1.9.4.tar.gz(r-4.4-noble)
lubridate_1.9.4.tgz(r-4.4-emscripten)lubridate_1.9.4.tgz(r-4.3-emscripten)
lubridate.pdf |lubridate.html✨
lubridate/json (API)
NEWS
# Install 'lubridate' in R: |
install.packages('lubridate', repos = c('https://tidyverse.r-universe.dev', 'https://cloud.r-project.org')) |
Bug tracker:https://github.com/tidyverse/lubridate/issues105 issues
Pkgdown site:https://lubridate.tidyverse.org
- lakers - Lakers 2008-2009 basketball data set
On CRAN:lubridate-1.9.4(2024-12-08)
Conda:r-lubridate-1.9.4(2025-03-25)
Last updated 3 months agofrom:fea9692686. Checks:12 OK. Indexed: yes.
Target | Result | Latest binary |
---|---|---|
Doc / Vignettes | OK | Mar 10 2025 |
R-4.5-win-x86_64 | OK | Mar 10 2025 |
R-4.5-mac-x86_64 | OK | Mar 10 2025 |
R-4.5-mac-aarch64 | OK | Mar 10 2025 |
R-4.5-linux-x86_64 | OK | Mar 10 2025 |
R-4.4-win-x86_64 | OK | Mar 10 2025 |
R-4.4-mac-x86_64 | OK | Mar 10 2025 |
R-4.4-mac-aarch64 | OK | Mar 10 2025 |
R-4.4-linux-x86_64 | OK | Mar 10 2025 |
R-4.3-win-x86_64 | OK | Mar 10 2025 |
R-4.3-mac-x86_64 | OK | Mar 10 2025 |
R-4.3-mac-aarch64 | OK | Mar 10 2025 |
Exports:%--%%m-%%m+%%within%add_with_rollbackamArithas_dateas_datetimeas.difftimeas.durationas.intervalas.periodceiling_dateComparecyclic_encodingdateDatedate_decimaldate<-dayday<-daysdays_in_monthddaysdecimal_datedhoursdmicrosecondsdmillisecondsdminutesdmonthsdmydmy_hdmy_hmdmy_hmsdnanosecondsdpicosecondsdsecondsdstdurationdweeksdyearsdymepiweekepiyearfast_strptimefit_to_timelinefloor_dateforce_tzforce_tzsformat_ISO8601guess_formatshmhmshourhour<-hoursint_alignsint_diffint_endint_end<-int_flipint_lengthint_overlapsint_shiftint_standardizeint_startint_start<-intersectintervalis.Dateis.difftimeis.durationis.instantis.intervalis.periodis.POSIXctis.POSIXltis.POSIXtis.timepointis.timespanisoweekisoyearleap_yearlocal_timemake_datemake_datetimemake_difftimemdaymday<-mdymdy_hmdy_hmmdy_hmsmicrosecondsmillisecondsminuteminute<-minutesmonthmonth<-msmymydNA_Date_NA_POSIXct_nanosecondsnoworiginparse_date_timeparse_date_time2periodperiod_to_secondspicosecondspmPOSIXctpretty_datesqdayqday<-quarterreclass_datereclass_timespanrollbackrollbackwardrollforwardround_datesecondsecond<-secondsseconds_to_periodsemestersetdiffshowstampstamp_datestamp_timetime_lengthtodaytztz<-unionwdaywday<-weekweek<-weekswith_tzydayyday<-ydmydm_hydm_hmydm_hmsyearyear<-yearsymymdymd_hymd_hmymd_hmsyq
Dependencies:cpp11genericstimechange
Citation
To cite lubridate in publications use:
Garrett Grolemund, Hadley Wickham (2011). Dates and Times Made Easy with lubridate. Journal of Statistical Software, 40(3), 1-25. URL https://www.jstatsoft.org/v40/i03/.
Corresponding BibTeX entry:
@Article{, title = {Dates and Times Made Easy with {lubridate}}, author = {Garrett Grolemund and Hadley Wickham}, journal = {Journal of Statistical Software}, year = {2011}, volume = {40}, number = {3}, pages = {1--25}, url = {https://www.jstatsoft.org/v40/i03/}, }
Readme and manuals
output: github_document
lubridate

Overview
Date-time data can be frustrating to work with in R. R commands for date-times are generally unintuitive and change depending on the type of date-time object being used. Moreover, the methods we use with date-times must be robust to time zones, leap days, daylight savings times, and other time related quirks, and R lacks these capabilities in some situations. Lubridate makes it easier to do the things R does with date-times and possible to do the things R does not.
If you are new to lubridate, the best place to start is the date and times chapter in R for data science.
Installation
# The easiest way to get lubridate is to install the whole tidyverse:
install.packages("tidyverse")
# Alternatively, install just lubridate:
install.packages("lubridate")
# Or the development version from GitHub:
# install.packages("devtools")
# devtools::install_github("tidyverse/lubridate")
install.packages("lubridate", repos = c('https://tidyverse.r-universe.dev', 'https://cloud.r-project.org'))
Cheatsheet
Features
library(lubridate, warn.conflicts = FALSE)
-
Easy and fast parsing of date-times:
ymd()
,ymd_hms
,dmy()
,dmy_hms
,mdy()
, ...ymd(20101215) #> [1] "2010-12-15" mdy("4/1/17") #> [1] "2017-04-01"
-
Simple functions to get and set components of a date-time, such as
year()
,month()
,mday()
,hour()
,minute()
andsecond()
:bday <- dmy("14/10/1979") month(bday) #> [1] 10 wday(bday, label = TRUE) #> [1] Sun #> Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat year(bday) <- 2016 wday(bday, label = TRUE) #> [1] Fri #> Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
-
Helper functions for handling time zones:
with_tz()
,force_tz()
time <- ymd_hms("2010-12-13 15:30:30") time #> [1] "2010-12-13 15:30:30 UTC" # Changes printing with_tz(time, "America/Chicago") #> [1] "2010-12-13 09:30:30 CST" # Changes time force_tz(time, "America/Chicago") #> [1] "2010-12-13 15:30:30 CST"
Lubridate also expands the type of mathematical operations that can be performed with date-time objects. It introduces three new time span classes borrowed from https://www.joda.org.
-
durations
, which measure the exact amount of time between two points -
periods
, which accurately track clock times despite leap years, leap seconds, and day light savings time -
intervals
, a protean summary of the time information between two points
Code of Conduct
Please note that the lubridate project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Help Manual
Help page | Topics |
---|---|
Add and subtract months to a date without exceeding the last day of the new month | %m+% %m+%,ANY,ANY-method %m+%,ANY,Duration-method %m+%,ANY,Interval-method %m+%,ANY,Period-method %m+%,Duration,ANY-method %m+%,Interval,ANY-method %m+%,Period,ANY-method %m-% %m-%,ANY,ANY-method %m-%,ANY,Duration-method %m-%,ANY,Interval-method %m-%,ANY,Period-method %m-%,Duration,ANY-method %m-%,Interval,ANY-method %m-%,Period,ANY-method add_with_rollback m+ m- |
Does a date (or interval) fall within an interval? | %within% %within%,ANY,Interval-method %within%,Date,list-method %within%,Interval,Interval-method %within%,Interval,list-method %within%,POSIXt,list-method |
Does date time occur in the am or pm? | am pm |
Convert an object to a date or date-time | as_date as_date,ANY-method as_date,character-method as_date,numeric-method as_date,POSIXt-method as_datetime as_datetime,ANY-method as_datetime,character-method as_datetime,Date-method as_datetime,numeric-method as_datetime,POSIXt-method |
Change an object to a duration | as.duration as.duration,character-method as.duration,difftime-method as.duration,Duration-method as.duration,Interval-method as.duration,logical-method as.duration,numeric-method as.duration,Period-method |
Change an object to an 'interval' | as.interval as.interval,difftime-method as.interval,Duration-method as.interval,Interval-method as.interval,logical-method as.interval,numeric-method as.interval,Period-method as.interval,POSIXt-method |
Change an object to a period | as.period as.period,character-method as.period,difftime-method as.period,Duration-method as.period,Interval-method as.period,logical-method as.period,numeric-method as.period,Period-method |
Cyclic encoding of date-times | cyclic_encoding |
Get/set date component of a date-time | date date<- |
Converts a decimal to a date | date_decimal |
Changes the components of a date object | DateTimeUpdate update.POSIXt |
Get/set days component of a date-time | day day<- mday mday<- qday qday<- wday wday<- yday yday<- |
Get the number of days in the month of a date-time | days_in_month |
Converts a date to a decimal of its year | decimal_date |
Get *d*aylight *s*avings *t*ime indicator of a date-time | dst |
Create a duration object. | ddays dhours dmicroseconds dmilliseconds dminutes dmonths dnanoseconds dpicoseconds dseconds duration dweeks dyears is.duration |
Duration class | Duration-class durations |
Fit a POSIXlt date-time to the timeline | fit_to_timeline |
Replace time zone to create new date-time | force_tz force_tz.default force_tzs |
Format in ISO8601 character format | format_ISO8601 format_ISO8601,Date-method format_ISO8601,Duration-method format_ISO8601,Interval-method format_ISO8601,Period-method format_ISO8601,POSIXt-method |
Guess possible date-times formats from a character vector | guess_formats |
Get/set hours component of a date-time | hour hour<- |
Utilities for creation and manipulation of 'Interval' objects | %--% interval int_aligns int_diff int_end int_end<- int_flip int_length int_overlaps int_shift int_standardize int_start int_start<- is.interval |
Interval class | Interval-class intervals |
Various date utilities | Date is.Date NA_Date_ |
Is x a difftime object? | is.difftime |
Is x a date-time object? | instant instants is.instant is.timepoint |
Various POSIX utilities | is.POSIXct is.POSIXlt is.POSIXt NA_POSIXct_ POSIXct |
Is x a length of time? | is.timespan |
Lakers 2008-2009 basketball data set | lakers |
Is a year a leap year? | leap_year |
Get local time from a date-time vector. | local_time |
Efficient creation of date-times from numeric representations | make_date make_datetime |
Create a difftime object. | make_difftime |
Get/set minutes component of a date-time | minute minute<- |
Get/set months component of a date-time | month month<- |
Parse periods with *h*our, *m*inute, and *s*econd components | hm hms ms |
The current day and time | now today |
1970-01-01 UTC | origin |
User friendly date-time parsing functions | fast_strptime parse_date_time parse_date_time2 |
Create or parse period objects | days hours is.period microseconds milliseconds minutes months.numeric nanoseconds period periods picoseconds seconds weeks years |
Contrive a period to/from a given number of seconds | period_to_seconds seconds_to_period |
Computes attractive axis breaks for date-time data | pretty_dates |
Get the fiscal quarter and semester of a date-time | quarter semester |
Roll backward or forward a date the previous, current or next month | rollback rollbackward rollforward |
Round, floor and ceiling methods for date-time objects | ceiling_date floor_date round_date |
Get/set seconds component of a date-time | second second<- |
Format dates and times based on human-friendly templates | stamp stamp_date stamp_time |
Compute the exact length of a time span | time_length time_length,Interval-method |
Description of time span classes in lubridate | timespan timespans |
Get/set time zone component of a date-time | tz tz<- |
Get/set weeks component of a date-time | epiweek isoweek week week<- |
Get date-time in a different time zone | with_tz with_tz.default |
Get/set years component of a date-time | epiyear isoyear year year<- |
Parse dates with *y*ear, *m*onth, and *d*ay components | dmy dym mdy my myd ydm ym ymd yq |
Parse date-times with *y*ear, *m*onth, and *d*ay, *h*our, *m*inute, and *s*econd components. | dmy_h dmy_hm dmy_hms mdy_h mdy_hm mdy_hms ydm_h ydm_hm ydm_hms ymd_h ymd_hm ymd_hms |