Convert date character to POSIXct

Hello Everyone.

I am importing data from a CSV file that has a date column. When I import the data and use the str() command, I get the following:

str(mdata)
$ date: chr "2020/8/14 12:09:00" "2020/8/14 12:10:00" "2020/8/14 12:11:00" "2020/8/14 12:12:00" ...

I want to convert the data to POSIXct instead of chr.

When I use the following command:
mdata$date <- as.POSIXct(farmdata$date, format = "%Y-%m-%d %H:%M:%S", tx = "GMT")

This is what I get

str(mdata)
$ date: POSIXct, format: NA NA NA NA ..

Any idea why the dates are converted to NA?

Thank you,
Steve

Your data have slashes between the components of the dates so your format argument should have the same. Also, notice that I changed the tx argument to be tz.

as.POSIXct(farmdata$date, format = "%Y/%m/%d %H:%M:%S", tz = "GMT")

Thank you! That worked!