6

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

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
user369599
  • 81
  • 2

1 Answers1

6

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.

G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
  • To elaborate a tiny bit more, do what @BenBolker said, and then try `methods(as.POSIXct)`, and type first `as.POSIXct.Date` and then `as.POSIXct.default` at the command line. – Josh O'Brien Dec 16 '11 at 00:08
  • 2
    Its 5 hours before midnight - ie the offset between GMT and EST. – James Dec 16 '11 at 10:42