0

Here's my code:

last_date <- "Tue, 26 Jun 2018 08:58:10 -0700 (PDT)"
as.Date(as.POSIXct(last_date, format = "%a, %d %b %Y %H:%M:%S %z"))

The result is

[1] NA

Version information:

platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          5.0                         
year           2018                        
month          04                          
day            23                          
svn rev        74626                       
language       R                           
version.string R version 3.5.0 (2018-04-23)
nickname       Joy in Playing       

When I try the same code on another computer (R version 3.4.0), the result is, as expected,

[1] "2018-06-26"

Any idea on how to solve this? Thanks.

1 Answers1

1

I think your local time langage is not english... so it will fail:

Your solution:

Sys.setlocale("LC_TIME", "C")
last_date <- "Tue, 26 Jun 2018 08:58:10 -0700 (PDT)"
as.Date(as.POSIXct(last_date, format = "%a, %d %b %Y %H:%M:%S %z"))

The result:

[1] "2018-06-26"

NB: you might have to set it back to where it was for other tasks. In that case either restart R or perform:

store_loctime <- Sys.getlocale("LC_TIME")
Sys.setlocale("LC_TIME", "C")
# Your code

Sys.setlocale("LC_TIME", store_loctime)
Emmanuel-Lin
  • 1,848
  • 1
  • 16
  • 31