$datetime

The $datetime API variable provides helpers for working with dates/times and conversion between formats.

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireDateTime class also inherits all the methods and properties of: Wire.

Show $var?     Show args?       Only hookable?    

Common

NameReturnSummary 
$datetime->date()
string bool

Format a date, using PHP date(), strftime() or other special strings (see arguments).

 
$datetime->elapsedTimeStr($start)
string array

Render an elapsed time string

 
$datetime->isStrtotime($str)
None 
$datetime->relativeTimeStr($ts)
string

Given a unix timestamp (or date string), returns a formatted string indicating the time relative to now

$datetime->strftime(string $format)
string false

strftime() replacement function that works in PHP 8.1+ (though not locale aware)

 
$datetime->stringToTimestamp(string $str, string $format)
int

Given a date/time string and expected format, convert it to a unix timestamp

 
$datetime->strtodate(string $str)
string

Parse English textual datetime description into a formatted date string, or blank if not a date

 
$datetime->strtotime(string $str)
false int null

Parse about any English textual datetime description into a Unix timestamp using PHP’s strtotime()

 

Advanced

NameReturnSummary 
$datetime->convertDateFormat(string $format, string $type)
string

Given a PHP date() format, convert it to either 'js', 'strftime' or 'regex' format

 
$datetime->getDateFormats()
array

Return all predefined PHP date() formats for use as dates

 
$datetime->getTimeFormats()
array

Return all predefined PHP date() formats for use as times

 

Additional methods and properties

In addition to the methods and properties above, WireDateTime also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.252