A string of known format used to specify a datetime offset. For example, a RelativeDateString that represents "one
year from today" is written as
"+1y"
.
RelativeDateStrings are comprised of the following parts:
- direction: the direction in which the quantity applies - one of + or -
- quantity: the number of units of
time to apply - a number
- timeUnit: an abbreviated timeUnit to use - one of ms/MS (millisecond), s/S (second),
mn/MN (minute), h/H (hour), d/D (day), w/W (week), m/M (month), q/Q (quarter, 3-months), y/Y (year), dc/DC
(decade) or c/C (century).
The timeUnit is case sensitive. A lowercase timeUnit implies an exact offset, so
+1d
refers to the current date / time increased by exactly 24 hours. If the timeUnit is
uppercase, it refers to the start or end boundary of the period of time in question, so +1D
would
refer to the end of the day (23:39:59:999) tomorrow, and -1D
would refer to the start of the day
(00:00:00:000) yesterday. - [qualifier]: an optional timeUnit encapsulated in square-brackets and used to offset
the calculation - eg. if +1d is "plus one day", +1d[W] is "plus one day from the end of the current week". You
may also specify another complete RelativeDateString as the [qualifier], which offers more control - eg, +1d[+1W]
indicates "plus one day from the end of NEXT week".
This format is very flexible. Here are a few
example relative date strings:
+0D
: End of today. There are often multiple ways to represent the same
time using this system - for example this could also be written as -1ms[+1D]
-0D
:
Beginning of today.
+1W
: End of next week.
+1w[-0W]
: Beginning of next week.
+1w[-0D]
: Beginning of the current day of next week.