Convert Any Input to Parsed Date or Datetime


R excels at computing with dates, and times. Using typed representation for your data is highly recommended not only because of the functionality offered but also because of the added safety stemming from proper representation.

But there is a small nuisance cost in interactive work as well as in programming. Users must have told as.POSIXct() about a million times that the origin is (of course) the epoch. Do we really have to say it a million more times? Similarly, when parsing dates that are some recogniseable form of YYYYMMDD format, do we really have to manually convert from integer or numeric or factor or ordered to character first? Having one of several common separators and/or date / time month forms (YYYY-MM-DD, YYYY/MM/DD, YYYYMMDD, YYYY-mon-DD and so on, with or without times), do we really need a format string?

Or could a smart converter function do this? anytime() aims to be that general purpose converter returning a proper POSIXct (or Date) object nomatter the input (provided it was somewhat parseable), relying on Boost date_time for the (efficient, performant) conversion.


From Integer or Numeric or Factor or Ordered

Character: Simple

Character: ISO

Character: Textual month formats

Character: Dealing with DST

This shows an important aspect. When not working localtime (by overriding to UTC) the changing difference UTC is correctly covered (which the underlying Boost Date_Time library does not by itself).

Technical Details

The heavy lifting is done by a combination of Boost lexical_cast to go from anything to string representation which is then parsed by Boost Date_Time. We use the BH package to access Boost, and rely on Rcpp for a seamless C++ interface to and from R.


The code and functionality started (in a less complete or polished form) in the function parsePOSIXt, later renamed to toPOSIXt, in the RcppBDT package.


Works as expected. A few extensions planned.


The package is now on CRAN and can be installed via a standard


Code, issue tickets, … are at the GitHub repo.


Dirk Eddelbuettel


GPL (>= 2)

Initially created: Sun Sep 11 11:39:17 CDT 2016
Last modified: Wed Nov 7 21:26:39 CST 2018