WC_Product_CSV_Importer::parse_date_field()
Parse dates from a CSV. Dates requires the format YYYY-MM-DD and time is optional.
Method of the class: WC_Product_CSV_Importer{}
No Hooks.
Return
String|null
.
Usage
$WC_Product_CSV_Importer = new WC_Product_CSV_Importer(); $WC_Product_CSV_Importer->parse_date_field( $value );
- $value(string) (required)
- Field value.
WC_Product_CSV_Importer::parse_date_field() WC Product CSV Importer::parse date field code WC 7.7.0
public function parse_date_field( $value ) { if ( empty( $value ) ) { return null; } if ( preg_match( '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])([ 01-9:]*)$/', $value ) ) { // Don't include the time if the field had time in it. return current( explode( ' ', $value ) ); } return null; }