Skip to content

Instantly share code, notes, and snippets.

@ClaytonJY
Last active November 12, 2019 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClaytonJY/fa7656249a2176dc3380de4dbf1fafb0 to your computer and use it in GitHub Desktop.
Save ClaytonJY/fa7656249a2176dc3380de4dbf1fafb0 to your computer and use it in GitHub Desktop.
'origin' must be supplied
# built-in function for "today"
Sys.Date()
#> [1] "2019-11-11"

# Dates are actually just integers underneath
# we can coerce to integer to see that version of it
today_days <- as.integer(Sys.Date())
today_days
#> [1] 18211

# now if we try to turn that number back into a date, it breaks
as.POSIXct(today_days)
#> Error in as.POSIXct.numeric(today_days): 'origin' must be supplied

# we have to tell it what that number means
# by convention, it's days since the "Unix Epoch", which is Jan 1, 1970
# so we gotta remind it
as.POSIXct(today_days, origin = "1970-01-01")
#> [1] "1970-01-01 00:03:31 EST"

Created on 2019-11-11 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment