$sanitizer->date() method

Sanitize a date or date/time string, making sure it is valid, and return it

  • If no date $format is specified, date will be returned as a unix timestamp.
  • If given date in invalid format and can’t be made valid, or date is empty, NULL will be returned.
  • If $value is an integer or string of all numbers, it is always assumed to be a unix timestamp.
  • If $format and “strict” option specified, date will also validate for format and no out-of-bounds values will be converted.


// basic usage
$string = $sanitizer->date($value);

// usage with all arguments
$string = $sanitizer->date($value, $format = null, array $options = []);


valuestring, int

Date string or unix timestamp

format (optional)string, null

Format of date string ($value) in any wireDate(), date() or strftime() format.

options (optional)array

Options to modify behavior:

  • returnFormat (string): wireDate() format to return date in. If not specified, then the $format argument is used.
  • min (string|int): Minimum allowed date in $format or unix timestamp format. Null is returned when date is less than this.
  • max (string|int): Maximum allowed date in $format or unix timestamp format. Null is returned when date is more than this.
  • default (mixed): Default value to return if no value specified.
  • strict (bool): Force dates that don’t match given $format, or out of bounds, to fail. Requires $format. (default=false)

Return value

string int null

$sanitizer methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #519
    In the 519th issue of ProcessWire Weekly we'll check out a new third party module called RockForms, introduce the latest ProcessWire core updates, and more. Read on!
    Weekly.pw / 20 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer