SteveS
SteveS

Reputation: 4040

Transform time - date to lubridate datetime object in R?

Here are some of the dates I have got in dataframe:

"23:46 13-08-2018" "00:10 14-08-2018" "01:09 14-08-2018" "05:53 14-08-2018" "06:09 14-08-2018" "06:11 14-08-2018" "06:25 14-08-2018"
"06:41 14-08-2018" "07:13 14-08-2018" "07:13 14-08-2018" "07:21 14-08-2018" "08:04 14-08-2018" "08:06 14-08-2018" "08:32 14-08-2018"
"08:33 14-08-2018" "09:08 14-08-2018" "09:25 14-08-2018" "09:41 14-08-2018" "11:18 14-08-2018" "12:02 14-08-2018" "12:23 14-08-2018"

Generally speaking it's in hh:mm dd-mm-yyyy format.

I am trying to parse it with lubridate parse_date_time but without luck:

parse_date_time(df$transaction_time, "ymd HMS"):

[1] NA                        "2000-10-14 08:20:18 UTC" "2001-09-14 08:20:18 UTC" NA                        "2006-09-14 08:20:18 UTC"
   [6] "2006-11-14 08:20:18 UTC" NA                        NA                        NA                        NA                       
  [11] NA                        "2008-04-14 08:20:18 UTC" "2008-06-14 08:20:18 UTC" NA                        NA                       

Please advise, I am trying to play with the formats but it gives me NA's:

parse_date_time(df$transaction_time, "HMS ymd")

Upvotes: 0

Views: 203

Answers (1)

mrjoh3
mrjoh3

Reputation: 457

You just need to match the format of your date:

parse_date_time("23:46 13-08-2018", "H:M d-m-y")

Upvotes: 2

Related Questions