Simplest way to extract date from timestamp

ℕʘʘḆḽḘ picture ℕʘʘḆḽḘ · Oct 24, 2016 · Viewed 20.8k times · Source

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.

Answer

doron picture doron · May 28, 2018

This would probably be the simplest way:

date(timestamp)

It will return a date class and not a string.