0

日付列invoiceDateを持つテーブルがあります。その中で、invoiceDate の値が 28-02-13 のレコードがあります。

今、私は以下を使用して日付範囲間のレコードを取得します:

            $this->db->select('*');
    $this->db->from('salesinvoices');
    $dateone=date('Y-m-d',strtotime('26-02-13'));
    $datetwo=date('Y-m-d',strtotime('12-03-13'));
    $this->db->where('invoiceDate >=', $dateone);
    $this->db->where('invoiceDate <=', $datetwo);
    $query = $this->db->get();
    $results = $query->result();
    print_r($results);

私はいつも空のレコードを取得します:(

4

2 に答える 2

3

私の問題の根本を見つけました。Strtotime は、ダッシュをマイナス記号と見なして演算を実行します。これを使用して動作させました:

date('Y-m-d',strtotime(str_replace('-', '/', '2026-02-13')));

だから私はすべてのダッシュを / に置き換えました、そしてそれはうまくいきました。これが誰かに役立つことを願っています。

于 2013-02-26T13:38:13.453 に答える
1

私はあなたのコードを試しましたが、生成されたクエリは

SELECT * FROM "salesinvoices" 
WHERE "invoiceDate" >= '2026-02-13' 
AND "invoiceDate" <= '2012-03-13'

したがって、問題はstrtotimeにあり、日付を誤解しているようです。

于 2013-02-26T12:18:31.763 に答える