How to convert to Unix timestamp in R

How to covert this following timestamp

Blockquote
Fri Mar 27 12:01:01 2020
to Unixtimestamp.

or other way around.

Here are conversions in both directions.

as.POSIXct("Fri Mar 27 12:01:01 2020", format="%a %b %d %H:%M:%S %Y")
[1] "2020-03-27 12:01:01 MDT"
 
DATETIME <- lubridate::ymd_hms("2020-03-27 12:23:01")
 
format(DATETIME,"%a %b %d %H:%M:%S %Y")
[1] "Fri Mar 27 12:23:01 2020"
1 Like

But what if the read time format into table
**** "Fri Mar 27 12:01:01 2020"**
is of type character()
The following table has column (stratPtime)

image

If I use this

as.POSIXct("Fri Mar 27 12:01:01 2020", format="%a %b %d %H:%M:%S %Y")

I get NA in stratPtime column.

this image shows the NA in stratPtime column
image

Please post the output of

dput(head(DF))

where you replace DF with the name of your data frame. I can then work with a sample of your actual data.

df_test$startPtime <- as.numeric(strptime(df_test$startPtime, "%a %b %d %H:%M:%S %Y"))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.