About Dynamic Relative Date-time Range
Dynamic Relative Date-time Range (also known as a Rolling Date Range) is a string formatted representation of a period of time relative to the present time in string form (like in an HTML form). Generally DRDR would be used in reporting environments as it provides a dynamic way to allow a predetermined selection.
Using this form allows coders and non-coders to easily read and write relative ranges. This can also be easily stored in a database for automated reporting.
This syntax requires a language with support similar to PHP's relative date syntax.
Caret (^) represents the range separator always separating the starting relative date from the ending relative date. When you begin with a caret or end with a caret, the omitted value is assumed as "now".
last-year^ == last-year^now
The term "ago" can be provided as per PHP relative date syntax documentation to indicate a previous relative date or time.
12-months-ago^now (or) 12-months-ago^
DRDR Example Formats
jan-1^now (or) jan-1^
now^next-year-jan-1 (or) ^next-year-jan-1
<option name="90-days-ago^now">Last 90 Days</option>
<option name="last-month^this-month">Last Month</option>
<option name="30-days-ago^now">Last 30 Days</option>
<option name="last-week^this-week">Last Week</option>
<option name="7-days-ago^now">Last 7 Days</option>
list($start_range, $end_range) = explode('^', $_REQUEST['date-range']);
$start_datetime = strtotime(str_replace('-', ' ', $start_range ?: 'now'));
$end_datetime = strtotime(str_replace('-', ' ', $end_range ?: 'now'));
Currently, I have plans to extends this format to include quarters, but have not yet done so.