Automattic\WooCommerce\Internal\DataStores\Orders
OrdersTableQuery::date_to_date_query_arg()
Generates a WP_Date_Query compatible query from a given date. YYYY-MM-DD queries have 'day' precision for backwards compatibility.
Method of the class: OrdersTableQuery{}
No Hooks.
Return
Array
. An array with keys 'year', 'month', 'day' and possibly 'hour', 'minute' and 'second'.
Usage
// private - for code of main (parent) class only $result = $this->date_to_date_query_arg( $date ): array;
- $date(mixed) (required)
- The date. Can be a WC_DateTime{}, a timestamp or a string.
OrdersTableQuery::date_to_date_query_arg() OrdersTableQuery::date to date query arg code WC 9.7.1
private function date_to_date_query_arg( $date ): array { $result = array( 'year' => '', 'month' => '', 'day' => '', ); $precision = null; if ( is_numeric( $date ) ) { $date = new \WC_DateTime( "@{$date}", new \DateTimeZone( 'UTC' ) ); $precision = 'second'; } elseif ( ! is_a( $date, 'WC_DateTime' ) ) { // For backwards compat (see https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query#date) // only YYYY-MM-DD is considered for date values. Timestamps do support second precision. $date = wc_string_to_datetime( date( 'Y-m-d', strtotime( $date ) ) ); $precision = 'day'; } $result['year'] = $date->date( 'Y' ); $result['month'] = $date->date( 'm' ); $result['day'] = $date->date( 'd' ); if ( 'second' === $precision ) { $result['hour'] = $date->date( 'H' ); $result['minute'] = $date->date( 'i' ); $result['second'] = $date->date( 's' ); } return $result; }