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

Twitter updates

  • New post: ProcessWire 3.0.131 adds support for partial/resumable downloads and http stream delivery, and contains several updates to our comments system, among other updates— More
    3 May 2019
  • New post: Quietly and without interruption this week, the ProcessWire.com website (and all subdomains) moved from a single static server to a load-balanced multi-server environment, giving us even more horsepower and redundancy than before— More
    19 April 2019
  • New post: With ProcessWire 3.0.130, this week we’ll take a detailed look at a few useful new API additions made in the last few weeks, along with examples of each—More
    12 April 2019

Latest news

  • ProcessWire Weekly #262
    The 262nd issue of ProcessWire Weekly will cover the latest module updates, both Pro modules and non-commercial ones. We've also got some highlights from the support forum, and a beautiful new site of the week. Read on!
    Weekly.pw / 18 May 2019
  • Lots of module updates
    In this post we take a quick look at the new version of ProFields Repeater Matrix, yet another new version of FormBuilder, and a new version of the GoogleClientAPI module.
    Blog / 17 May 2019
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH