TOP ▲
itcore TOP
> TIPS
> mysql_dt.php
タグ:mysql datetime 非互換 MySQL 5.6.4 datetime 非互換に対する検索クエリの修正| itcore 2017年
select * from table1 where dt = '2017/10/01';
これを以下に変換する。
select * from table1 where dt = '2017-10-01 00:00:00';
関数で変換する。
select * from table1 where dt = uDT_Conv('2017/10/01');
function uDT_Conv($dt) {
// "2017/10/01" => "2017-10-01 00:00:00";
if (10 != strlen($dt)) return $dt; // 形式が違う場合
$dt2 = substr($dt, 0, 4) . "-" . substr($dt, 5, 2) . "-" . substr($dt, 8, 2) . " 00:00:00";
//echo "debug dt=$dt $dt2=$dt2<br>\n";
return $dt2;
}