Reputation: 133
This seems like a really easy question, but 30 mins of Googling didn't solve it:
How can I convert a Date (YYYY-MM-DD) to a character with the typical American format (MM/DD/YYYY)? In other words, I know I can use as.Date(dt, format = "%Y-%m-%d") to specify the format of the input date, but how can I specify the format of the output??
dt = "2013-04-19"
as.Date(dt, format = "%Y-%m-%d")
[1] "2013-04-19" #### NOT what I want
as.character(as.Date(dt, format = "%Y-%m-%d"))
[1] "2013-04-19" #### Also NOT what I want
"04/19/2013" Is what I want
Many thanks!
Upvotes: 2
Views: 231
Reputation: 1015
format(as.Date(dt, format = "%Y-%m-%d"), "%m/%d/%Y")
[1] "04/19/2013"
Upvotes: 4