Automattic\WooCommerce\Utilities
TimeUtil::is_valid_date
Check if a string represents a valid date in a given format.
Method of the class: TimeUtil{}
No Hooks.
Returns
true|false
. True if $date represents a valid date/time according to $format, false otherwise.
Usage
$result = TimeUtil::is_valid_date( $date, $format ): bool;
- $date(string) (required)
- The date string to check.
- $format(string)
- The format to verify the date string against.
Default: 'Y-m-d H:i:s'
TimeUtil::is_valid_date() TimeUtil::is valid date code WC 9.9.5
public static function is_valid_date( string $date, string $format = 'Y-m-d H:i:s' ): bool { $d = DateTime::createFromFormat( $format, $date ); return $d && $d->format( $format ) === $date; }