| Title: | Simple and Fast Date Manipulation on Character Strings |
|---|---|
| Description: | Provides simple and fast date manipulation functions operating on character strings in one of three formats: 'DD.MM.YYYY' (default), 'YYYY-MM-DD' or 'YYYYMMDD'. The format is chosen once per R session. Functions include extraction of day, month, and year components, computation of differences between two dates, and addition or subtraction of months. "DD" is ignored in the calculations, therefore a date like 31.02.2026 is a valid in- or output. That's why it is so fast. |
| Authors: | Prem Lueers [aut, cre] (ORCID: <https://orcid.org/0009-0003-3315-1438>) |
| Maintainer: | Prem Lueers <[email protected]> |
| License: | LGPL-3 |
| Version: | 1.1.0 |
| Built: | 2026-10-16 15:01:29 UTC |
| Source: | https://github.com/cran/theRefdate |
Adds or subtracts a number of whole months to or from a date. The day is left unchanged.
dateAddMonths(termin, monthsToBeAdded, format = .zustand$name)dateAddMonths(termin, monthsToBeAdded, format = .zustand$name)
termin |
start date in the format of the flavour |
monthsToBeAdded |
number of whole months (positive: add, negative: subtract) |
format |
flavour; the default is the one set with |
Invalid input, including NA and the empty string, is an error (version 1.0.0 returned NA).
date in the format of the flavour
dateAddMonths("01.01.2000", -3 ) == "01.10.1999"dateAddMonths("01.01.2000", -3 ) == "01.10.1999"
Computes the difference between two dates in the format of the flavour. Returns the differences in years, months and total months as a named list.
dateDiff(frueher, spaeter, format = .zustand$name)dateDiff(frueher, spaeter, format = .zustand$name)
frueher |
earlier date in the format of the flavour |
spaeter |
later date in the format of the flavour |
format |
flavour; the default is the one set with |
Invalid input, including NA and the empty string, is an error (version 1.0.0 returned NA).
list with diffJ (years), diffM (months), diffDauer (duration in fractional years), diffDauerM (total months)
dateDiff("01.01.2000", "01.12.1999")$diffDauerM == -1dateDiff("01.01.2000", "01.12.1999")$diffDauerM == -1
Returns the active flavour (date format) of the package theRefdate.
flavour()flavour()
character string: "dmy" (DD.MM.YYYY), "iso" (YYYY-MM-DD) or
"iso_basic" (YYYYMMDD). The default is "dmy". Version 1.0.0 returned
"LP" for this format.
flavour() == "dmy"flavour() == "dmy"
Extracts the year from a date string as 'numeric'.
jahr(datumstring, format = .zustand$name)jahr(datumstring, format = .zustand$name)
datumstring |
date string in the format of the flavour (default "DD.MM.YYYY") |
format |
flavour; the default is the one set with |
Invalid input, including NA and the empty string, is an error (version 1.0.0 returned NA).
numeric
jahr("02.02.2002") == 2002jahr("02.02.2002") == 2002
Extracts the month from a date string as 'numeric'.
monat(datumstring, format = .zustand$name)monat(datumstring, format = .zustand$name)
datumstring |
date string in the format of the flavour (default "DD.MM.YYYY") |
format |
flavour; the default is the one set with |
Invalid input, including NA and the empty string, is an error (version 1.0.0 returned NA).
numeric
monat("02.02.2000") == 2monat("02.02.2000") == 2
Sets the flavour (date format) used by all functions of the package as long as
they are called without their own argument format.
The setting is valid for the whole R session. Changing it to a different
flavour after it has been set once gives a warning.
If setFlavour is never called, the package works in the format
DD.MM.YYYY ("dmy") and returns the same results as version 1.0.0 for
every valid input.
setFlavour(flavour)setFlavour(flavour)
flavour |
|
the flavour that was set (invisibly)
setFlavour( "iso" ) jahr( "2002-02-02" ) == 2002 setFlavour( "dmy" )setFlavour( "iso" ) jahr( "2002-02-02" ) == 2002 setFlavour( "dmy" )
Extracts the day from a date string as 'numeric'.
tag(datumstring, format = .zustand$name)tag(datumstring, format = .zustand$name)
datumstring |
date string in the format of the flavour (default "DD.MM.YYYY") |
format |
flavour; the default is the one set with |
Invalid input, including NA and the empty string, is an error (version 1.0.0 returned NA).
numeric
tag("03.02.2000") == 3tag("03.02.2000") == 3