Transforming a long date string to a Date in R

I have a date variable that is formatted as:

25-APR-2013 03.05.03.000000000 PM

I have converted it to a character and tried to get it to format. I did use the help documentation for as.Date but it did not help me.

I am trying to find a solution to get this into a Date type of the standard %Y-%m-%d

> df$DELETE_DATE
[1] "01-JUN-2011 05.24.12.000000000 AM" 
[2]"01-SEP-2011 03.54.01.000000000 AM" 
[3]"01-SEP-2012 05.20.10.000000000 AM"
[4] "01-JAN-2013 02.45.55.000000000 AM" 

This is 4 out of 3.6 million.

I am open to any suggestions. Thanks

Answers


If you just want the date, then just specify that portion in the format argument:

as.Date("25-APR-2013 03.05.03.000000000 PM","%d-%b-%Y")
#[1] "2013-04-25"

If you wanted the full date-time, use as.POSIXct with a custom format:

as.POSIXct("25-APR-2013 03.05.03.000000000 PM",format="%d-%b-%Y %I.%M.%OS %p")
#[1] "2013-04-25 15:05:03 CDT"

Need Your Help

Persistent connection between a WAN and a LAN server

websocket long-polling lan wan

We need to have a persistent connection between servers on WAN and LAN. Basically multiple LAN servers have to register with a server on Internet and always keep an open connection, because we can ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.