はい、それは私がキーとして数値月でスペイン語の月連想配列内のリストこのカスタム関数で可能である、と私はのstrtotime()関数を介して出力にそれを日付を並べ替えます。この関数は、 'now'をパラメータとして現在の時刻を返すこともできます。このコードは、あなたのアクティブな子テーマやテーマのfunction.phpファイルに行く
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);
}
:
これは、関数のコードです。日付がseptiembre 1, 2016
のようなまたは(昏睡の後にスペースなし)septiembre 1,2016
のようなものである場合
私は本当に知らないとして、あなたは上記のコードでは、コメントの代替を見つけるでしょう。
もfebrero, 2016
またはfebrero 2016
日付フォーマットのための私のコードの作品は。
私は$month_arr
配列にある月の名前のいずれかのミスをしていないことを確認してください...
用途:
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
}
それはではないでしょうSQL側の日付を比較する方が有益でしょうか?それはあなたの条件に一致するものだけ、すべての行の往復とメモリを必要としません。 – ppeterka
'var_dump($ row2 [" meta_value "])'から何を得るのですか? –
私はこれを例としています:string(12) "febrero 2017"またはstring(18) "septiembre 1、2016" – Carl35