Version: v0.7.1 - Beta.  We welcome contributors & feedback.

Date Strings

Overview 

Most Date methods accept a date string argument in place of a Date object.

A date strings can be an absolute date (e.g. “2021-10-27”) or a relative date (e.g. “3 days ago”).

Almost any kind of format can be parsed. Formats can be mixed together, and most separators (e.g. hyphens, slashes) are accepted.

As a shortcut, you may also create a Date object using TypeString syntax. (e.g. date'2021-03-24', date'last sunday')

Absolute Date Strings 

Here are some examples (not limited to these):

February 12, 2021  // Full month name
Feb 9, 2021        // Short month name
Feb 09, 2021       // Leading zeroes
Feb 9th, 2021      // English suffix
Feb-09-2021        // Separators

Feb 9, 2021, 16:43:00  // Full time
Feb 9, 2021, 4:08 AM   // AM/PM
Feb 9, 2021, 5PM       // AM/PM short

2021-02-09 16:43:00 +0800  // Timezone offset
2021-02-09 16:43:00 PST    // Timezone Code

@1215282385          // Unix timestamp
2008-08-07 18:11:31  // MySQL
20080701T22:38:07    // XMLRPC

Relative Date Strings 

// Future
5 days
+5 weeks

// Past
-5 weeks
5 weeks ago
3 days ago

// First/Last/Next
last Sunday
next Monday
last day of March
first day of next month
last Wed of July 2021
5th weekday of June

// Dates (starting at midnight)
yesterday
today
tomorrow

// Times
midnight
now
noon

// Combined
next Sunday 5PM
yesterday noon
next month + 2 days
last day of March -1 day

For more detail, see PHP's Relative Formats.