Question: I am having a problem with date & time format in R.

my R code is having the format: "%m/%d/%y %H:%M". Example: "02/05/18 00:29"

But,I have datasets with different type of formats like "%Y-%m-%d %H:%M:%S", etc

I am trying to write a R code where all type of format will be converted into the format "%m/%d/%y %H:%M".

```
x <- "2018-02-27 00:03:45"
x <- as.POSIXct(x, format = '%m/%d/%y %H:%M')

```

But, I am getting NA. Please help!

Answer: 
Use lubridate package.

```
library(lubridate)
> d = '2018-02-27 00:03:45'
> parse_date_time(d, orders = 'ymd HMS')
[1] "2018-02-27 00:03:45 UTC"

```
You can use `lubridate` package for heterogeneous date-time data. The `parse_date_time` provide you option to define many formats in which one can expect date/time in the date. 

```
#Many different formats of date/time data
x <- c("17-01-01", "170502", "18-01 03", "18-01-03 12:02", "2018-01-03 12:02:15",
       "2018-02-27 00:03:45", "2018-02-27 00:03")
#Defined 3 different types of formatting for parse_date_time
parse_date_time(x, c("ymd", "ymd HM", "ymd HMS"))

#Result
[1] "2017-01-01 00:00:00 UTC" "2017-05-02 00:00:00 UTC" "2018-01-03 00:00:00 UTC"
[4] "2018-01-03 12:02:00 UTC" "2018-01-03 12:02:15 UTC" "2018-02-27 00:03:45 UTC"
[7] "2018-02-27 00:03:00 UTC"

```