'Is there an R function for changing a strange character date to POSIXct?

My date type looks like 7-Feb-20 (character) data, and I need to convert this into a data/time, so eventually I can use "As.Date() or as.POSIXct()" to move it into the SQL server as datetime. SQL server uses datetime as default when moving from R to SQL.



Solution 1:[1]

The as.Date() function will convert character data into a date format.

You can specify the input format by using the format = argument.

In this case, it looks like your format is %d-%b-%y

  • %d will give you day
  • %b will give you abbreviated month name (compare with %B, which gives full month name)
  • %y will give you two-digit year.

You will also need to include the hyphen in your format.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shane Smith