CodeIgniter Forums
Date comparison - Less than 24 Hours in Models - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Date comparison - Less than 24 Hours in Models (/showthread.php?tid=91070)



Date comparison - Less than 24 Hours in Models - Anharr - 06-12-2024

I have the following queries in CodeIgniter to find any data in which the date_created field is less than 24 hours. 
Here is my code in Models


Code:
public function checkDeposit($preOrder)
    {
        return $this->db->table('deposit')
        ->where('preorder_code', $preOrder)
        ->where('status', 0)
        ->where('date_created <', strtotime(date('YmdHis'), INTERVAL 1 DAY))
        ->get()
        ->getRowArray();
    }


But the above query is not working.
What I want in short is, return all rows which the date_created is less than 24 hours.
My date_created format is Unix TimeStamp (1718204380)
How to get data less than 24 hours in Models ?


RE: Date comparison - Less than 24 Hours in Models - kenjis - 06-12-2024

The code "strtotime(date('YmdHis'), INTERVAL 1 DAY)" causes "PHP Parse error".


RE: Date comparison - Less than 24 Hours in Models - paulkd - 06-13-2024

(06-12-2024, 09:32 AM)Anharr Wrote: I have the following queries in CodeIgniter to find any data in which the date_created field is less than 24 hours. 
Here is my code in Models


Code:
public function checkDeposit($preOrder)
    {
        return $this->db->table('deposit')
        ->where('preorder_code', $preOrder)
        ->where('status', 0)
        ->where('date_created <', strtotime(date('YmdHis'), INTERVAL 1 DAY))
        ->get()
        ->getRowArray();
    }


But the above query is not working.
What I want in short is, return all rows which the date_created is less than 24 hours.
My date_created format is Unix TimeStamp (1718204380)
How to get data less than 24 hours in Models ?

Hi,

I'm not sure I fully understand your requirements but I think the following would bring back records "within the past 24 hours"

Code:
->where('date_created >', strtotime("-1 day"))



RE: Date comparison - Less than 24 Hours in Models - Anharr - 06-13-2024

(06-13-2024, 02:40 AM)paulkd Wrote:
(06-12-2024, 09:32 AM)Anharr Wrote: I have the following queries in CodeIgniter to find any data in which the date_created field is less than 24 hours. 
Here is my code in Models


Code:
public function checkDeposit($preOrder)
    {
        return $this->db->table('deposit')
        ->where('preorder_code', $preOrder)
        ->where('status', 0)
        ->where('date_created <', strtotime(date('YmdHis'), INTERVAL 1 DAY))
        ->get()
        ->getRowArray();
    }


But the above query is not working.
What I want in short is, return all rows which the date_created is less than 24 hours.
My date_created format is Unix TimeStamp (1718204380)
How to get data less than 24 hours in Models ?

Hi,

I'm not sure I fully understand your requirements but I think the following would bring back records "within the past 24 hours"

Code:
->where('date_created >', strtotime("-1 day"))


Greaatttt ! Thank you !