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.
In MySQL, use the DATE() function to retrieve the date from a datetime or timestamp value. This function takes only one argument – either an expression which returns a date/datetime/ timestamp value or the name of a timestamp/datetime column.
While working with Excel, we can extract only the date portion by using the INT or TRUNC function.
You can simply use the fromtimestamp function from the DateTime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the corresponding DateTime object to timestamp.
This would probably be the simplest way:
date(timestamp)
It will return a date class and not a string.
Use date instead of day
lubridate::date(timestamp)
There is also data.table
s as.IDate()
function now:
timestamp <- "2011-08-10 14:00:00"
data.table::as.IDate(timestamp)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With