Skip to contents

Given a start date-time, end date-time and time resolution seq_dttm() generates a regular sequence of date-time strings is generated. The start and end date-times must be a string or numeric of the form YYYYMMDD, YYYYMMDDhh, YYYYMMDDhhmm, or YYYYMMDDhhmmss.

The output sequence is a vector of strings. Truncation of the strings is done so that the last zero values are removed.

seq_secs(), seq_mins(), seq_hours() and seq_days() generate regular sequences of numbers as character vectors with a character specifying the time unit. These vectors can be used to, for example, generate sequences of lead times for input to functions such as read_forecast. to_seconds can be used to convert any of the

Usage

seq_dttm(start_dttm, end_dttm, by = "1h")

seq_secs(from, to, by = 1)

seq_mins(from, to, by = 1)

seq_hours(from, to, by = 1)

seq_days(from, to, by = 1)

Arguments

start_dttm

The date-time at the start of the sequence. Must be a string or numeric of the form YYYYMMDD, YYYYMMDDhh, YYYYMMDDhhmm, or YYYYMMDDhhmmss.

end_dttm

The date-time at the end of the sequence. Must be a string or numeric of the form YYYYMMDD, YYYYMMDDhh, YYYYMMDDhhmm, or YYYYMMDDhhmmss.

by

Increment of the sequence. If numeric, it is considered to be in hours, otherwise a string with a number followed by a unit. Units can be "s", for seconds; "m", for minutes; "h", for hours; or "d", for days.

from, to

the starting and (maximal) end values of the sequence. Of length 1 unless just from is supplied as an unnamed argument.

Value

A sequence of date-time strings

Examples

seq_dttm(20220306, 20220307)
#>  [1] "2022030600" "2022030601" "2022030602" "2022030603" "2022030604"
#>  [6] "2022030605" "2022030606" "2022030607" "2022030608" "2022030609"
#> [11] "2022030610" "2022030611" "2022030612" "2022030613" "2022030614"
#> [16] "2022030615" "2022030616" "2022030617" "2022030618" "2022030619"
#> [21] "2022030620" "2022030621" "2022030622" "2022030623" "2022030700"
seq_dttm(20220306, 20220307, by = "30m")
#>  [1] "202203060000" "202203060030" "202203060100" "202203060130" "202203060200"
#>  [6] "202203060230" "202203060300" "202203060330" "202203060400" "202203060430"
#> [11] "202203060500" "202203060530" "202203060600" "202203060630" "202203060700"
#> [16] "202203060730" "202203060800" "202203060830" "202203060900" "202203060930"
#> [21] "202203061000" "202203061030" "202203061100" "202203061130" "202203061200"
#> [26] "202203061230" "202203061300" "202203061330" "202203061400" "202203061430"
#> [31] "202203061500" "202203061530" "202203061600" "202203061630" "202203061700"
#> [36] "202203061730" "202203061800" "202203061830" "202203061900" "202203061930"
#> [41] "202203062000" "202203062030" "202203062100" "202203062130" "202203062200"
#> [46] "202203062230" "202203062300" "202203062330" "202203070000"
seq_dttm(20220301, 20220331, by = "1d")
#>  [1] "20220301" "20220302" "20220303" "20220304" "20220305" "20220306"
#>  [7] "20220307" "20220308" "20220309" "20220310" "20220311" "20220312"
#> [13] "20220313" "20220314" "20220315" "20220316" "20220317" "20220318"
#> [19] "20220319" "20220320" "20220321" "20220322" "20220323" "20220324"
#> [25] "20220325" "20220326" "20220327" "20220328" "20220329" "20220330"
#> [31] "20220331"
seq_dttm(202203061030, 202203061045, by = "30s")
#>  [1] "20220306103000" "20220306103030" "20220306103100" "20220306103130"
#>  [5] "20220306103200" "20220306103230" "20220306103300" "20220306103330"
#>  [9] "20220306103400" "20220306103430" "20220306103500" "20220306103530"
#> [13] "20220306103600" "20220306103630" "20220306103700" "20220306103730"
#> [17] "20220306103800" "20220306103830" "20220306103900" "20220306103930"
#> [21] "20220306104000" "20220306104030" "20220306104100" "20220306104130"
#> [25] "20220306104200" "20220306104230" "20220306104300" "20220306104330"
#> [29] "20220306104400" "20220306104430" "20220306104500"
seq_secs(0, 60, 5)
#>  [1] "0s"  "5s"  "10s" "15s" "20s" "25s" "30s" "35s" "40s" "45s" "50s" "55s"
#> [13] "60s"
seq_mins(0, 60, 15)
#> [1] "0m"  "15m" "30m" "45m" "60m"
seq_hours(0, 6)
#> [1] "0h" "1h" "2h" "3h" "4h" "5h" "6h"
seq_hours(0, 6, 3)
#> [1] "0h" "3h" "6h"
seq_days(0, 7)
#> [1] "0d" "1d" "2d" "3d" "4d" "5d" "6d" "7d"
seq_days(0, 28, 7)
#> [1] "0d"  "7d"  "14d" "21d" "28d"