Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R as.POSIXct(Sys.Date()) returns date a day early

Tags:

time

r

posixct

What am I missing ?

Sys.Date()
[1] "2011-12-15"

as.POSIXct(Sys.Date())
[1] "2011-12-14 19:00:00 EST"  # Returning the day before !!

as.POSIXct(Sys.Date(), origin="1970-01-01 00:00:00")
[1] "2011-12-14 19:00:00 EST"  # Still returning day before !!

Sys.getlocale()
[1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;
LC_MONETARY=English_United States.1252;LC_NUMERIC=C;
LC_TIME=English_United States.1252"

Thanks for your help

like image 982
user369599 Avatar asked Dec 15 '11 22:12

user369599


1 Answers

Its likely a time zone problem. Try this:

as.POSIXct(format(Sys.Date()))

Note that Sys.time() also exists.

See R Help Desk article in R News 4/1 for some details on this.

like image 160
G. Grothendieck Avatar answered Oct 09 '22 16:10

G. Grothendieck