0

I have a date value "11/7/2016 11:51" which is currently in "mm/dd/yyyy hh:mm" format. I want to convert this date to "2016-11-07 11:51:00" i.e "yyyy-mm-dd hh:mm:ss" format using R language.

I would like to have any suggestions/help. Thanks in advance.. !!

2 Answers2

0

We can use as.POSIXct from base R

as.POSIXct( "11/7/2016 11:51" , format = "%m/%d/%Y %H:%M")
#[1] "2016-11-07 11:51:00 IST"

If we want to change the timezone, there is tz argument

akrun
  • 874,273
  • 37
  • 540
  • 662
0

Or mdy_hm from lubridate

lubridate::mdy_hm("11/7/2016 11:51")
[1] "2016-11-07 11:51:00 UTC"

lubridate will default to timezone UTC.

as.POSIXct will default to your (computer) timezone.

phiver
  • 23,048
  • 14
  • 44
  • 56