$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.

Usage

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

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

Arguments

NameType(s)Description
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 #549
    In the 549th issue of ProcessWire Weekly we’re going to check out the latest core updates, highlight one older yet still very relevant third party module, and more. Read on!
    Weekly.pw / 17 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.