Creating a Date Sequence

I would like to generate a date sequence with the following code:

vm1=strptime("2000-01-01 00:00:00", format="%Y-%m-%d %H:%M:%S")
vm2=strptime("2011-12-31 23:55:00", format="%Y-%m-%d %H:%M:%S")
vm3=seq(vm1, vm2, by = min(300))

The problem is that on some specific program, the date changes the time zone and skips part of the generated data. For instance:

vm3[24500:24510]

I would appreciate any help or instructions.

+5
source share
1 answer

This section vm3looks good to me (UK, time zone GMT/BST). Think about your dates being in universal time, and then later entered in your local time zone.

vm1=strptime("2000-01-01 00:00:00", format="%Y-%m-%d %H:%M:%S", tz = "UTC")
vm2=strptime("2011-12-31 23:55:00", format="%Y-%m-%d %H:%M:%S", tz = "UTC")
vm3=seq(vm1, vm2, by = "300 mins")
any(is.na(vm3)) #FALSE

By the way, you need an argument by "300 mins", not min(300). min- minimum function; it has nothing to do with minutes.

+7
source

All Articles