WooCommerce预订-在自定义日期格式上使用PHP比较两个时间戳

WooCommerce预订-在自定义日期格式上使用PHP比较两个时间戳,php,wordpress,date,woocommerce,timestamp,Php,Wordpress,Date,Woocommerce,Timestamp,使用,我正在开发一个系统,我必须用PHP比较两个日期 我有下一个sql查询来获取此日期: $consulta2="SELECT meta_value FROM pwkynbjbwoocommerce_order_itemmeta WHERE meta_key='Fecha de Reserva' AND order_item_id=".$row["order_item_id"]; Fecha de Reserva给我们一个西班牙日期,比如2016年9月或2016年9月12日 我想将一个日期

使用,我正在开发一个系统,我必须用PHP比较两个日期

我有下一个sql查询来获取此日期:

 $consulta2="SELECT meta_value FROM pwkynbjbwoocommerce_order_itemmeta WHERE  meta_key='Fecha de Reserva' AND order_item_id=".$row["order_item_id"];
Fecha de Reserva
给我们一个西班牙日期,比如2016年9月或2016年9月12日

我想将一个日期与“今天”进行比较,因此我尝试使用以下PHP代码:

 if (strtotime($row2["meta_value"])>time()){}
但它不起作用。

我如何才能做到这一点?


感谢

是的,使用此自定义函数,我可以在关联数组中列出以数字月为键的西班牙月份,并通过strotime()函数重新排序日期以输出它。此函数还可以以“now”作为参数返回当前时间

这是功能代码:

function bk_date( $date ) {

    // Removing the coma (if there is a coma + a space)
    $my_time = str_replace ( ',', '', $date );
    // or replacing the coma by a space (if there is a coma alone without a space)
    // $my_time = str_replace ( ',', ' ', $the_date );

    $my_time_arr = explode( ' ', $my_time );
    $my_time_count = count( $my_time_arr );
    $month = $my_time_arr[0];
    if ( count( $my_time_arr ) > 2 ) { // When there is the month, the day and the year
        // Formating the day in 2 digits
        $day = $my_time_arr[1] < 10 ? '0'.$my_time_arr[1] : $my_time_arr[1];
        $year = $my_time_arr[2];
    } else { // When there is the month, the day and the year
        $year = $my_time_arr[1];
    }
    // Array of spanish month
    $month_arr = array('01' => 'enero', '02' => 'febrero', '03' => 'marzo', '04' => 'abril', '05' => 'mayo', '06' => 'junio', '07' => 'julio', '08' => 'agosto', '09' => 'septiembre', '10' => 'octubre', '11' => 'noviembre', '12' => 'diciembre');

    // Browse the list of month and compare (when $value match, it's replace by the index $key
    foreach ( $month_arr as $key => $value ) {
        if ( $month == $value ) {
            $month = $key;
            break;
        }
    }
    if ( count( $my_time_arr ) > 2 )
        $result = $year . '-' . $month . '-' . $day;
    else
        $result = $year . '-' . $month;

    return $date == 'now' ? strtotime( $date ) : strtotime( $result );
}

在SQL端比较日期不是更有益吗?它不需要所有行的往返和内存,只需要那些符合您标准的行。您从变量转储($row2[“meta\u value”])中得到了什么??我有这样一个例子:string(12)“febrero 2017”或string(18)“septiembre 1,2016”
echo bk_date($row2["meta_value"]); // display the timestamp of your spanish date.

// Comparing 2 timestamps (bk_date('now') return the "current time").
if ( bk_date($row2["meta_value"]) > bk_date('now') ) {
    // do something
}