WC_Product_CSV_Importer::parse_date_field( string $value )

Parse dates from a CSV.


Description Description

Dates requires the format YYYY-MM-DD and time is optional.


Parameters Parameters

$value

(Required) Field value.


Top ↑

Return Return

(string|null)


Top ↑

Source Source

File: includes/import/class-wc-product-csv-importer.php

	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;
	}

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.