Search code examples
rdatetimelubridate

Simplest way to extract date from timestamp


Consider the following timestamp

timestamp <- ymd_hms("2011-08-10 14:00:00", tz = "Pacific/Auckland")

> timestamp
[1] "2011-08-10 14:00:00 NZST"

What is the simplest way to get the day part 2011-08-10 from it, and making sure this day is a proper date and not a string?

Using lubridate::day(timestamp) obviously fails here.


Solution

  • This would probably be the simplest way:

    date(timestamp)
    

    It will return a date class and not a string.