15

I tried:

seq(
     from=as.POSIXct("2012-1-1 0", tz="UTC"),
     to=as.POSIXct("2012-1-3 23", tz="UTC"),
     by="hour"
   )  

But I only get 1 hour(0:00:00) of the last day instead of 24 hours, actually any hour of the day resulted in only one hour(0:00:00), and I do want to have 2012-1-4.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Rosa
  • 1,793
  • 5
  • 18
  • 23

3 Answers3

25

Specify the time in full?

seq(
     from=as.POSIXct("2012-1-1 0:00", tz="UTC"),
     to=as.POSIXct("2012-1-3 23:00", tz="UTC"),
     by="hour"
   )  
thelatemail
  • 91,185
  • 12
  • 128
  • 188
5

You did not use a standard format for the dates. See ?as.POSIXct.

Try this

seq(from=as.POSIXct("2012-01-01 00:00:00", tz="UTC"), 
    to=as.POSIXct("2012-01-03 23:00:00", tz="UTC"), by="hour")
GSee
  • 48,880
  • 13
  • 125
  • 145
5

You could specify a format:

seq(
     from=as.POSIXct("2012-1-1 0","%Y-%m-%d %H", tz="UTC"),
     to=as.POSIXct("2012-1-3 23", "%Y-%m-%d %H", tz="UTC"),
     by="hour"
   )
IRTFM
  • 258,963
  • 21
  • 364
  • 487