1

I am converting dates formatted as "Mar.01" and I thought it would be straightforward to cast using standard formatting rules, but I have an issue with it.

For example, if I produce a date like so:

format(Sys.Date(), "%b%y")
[1] "May13"

I cannot convert it back to a date object using the same pattern::

as.Date(format(Sys.Date(), "%b%y"),"%b%y")
[1] NA

I tried escaping the latter format term with \\ but same result--NA. What did I miss?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ako
  • 3,569
  • 4
  • 27
  • 38

1 Answers1

1

You probably need to include a day in your date. You can paste() in a day to get around this.

x <- paste0(1, format(Sys.Date(), "%b%y"))
as.Date(x, "%d%b%y")
Ciarán Tobin
  • 7,306
  • 1
  • 29
  • 45