Home > front end >  convert string Jan 1, 2000 12:00 AM to date-time in r
convert string Jan 1, 2000 12:00 AM to date-time in r

Time:10-23

Real simple question that I can't quite find the right answer to.

How would I convert a string of convert string Jan 1, 2000 12:01 AM to date-time in r?

CodePudding user response:

The answer is hidden in ?strptime -

x <- "Jan 1, 2000 12:01 AM"
as.POSIXct(x, format = '%b %d, %Y %I:%M %p', tz = 'UTC')
#[1] "2000-01-01 00:01:00 UTC"

Or use lubridate -

lubridate::mdy_hm(x)
#[1] "2000-01-01 00:01:00 UTC"

CodePudding user response:

We may use parse_date

library(parsedate)
 parse_date(x)
[1] "2000-01-01 00:01:00 UTC"

data

x <- "Jan 1, 2000 12:01 AM"
  •  Tags:  
  • r
  • Related