Welcome Guest, Not a member yet? Register   Sign In
Date comparison - Less than 24 Hours in Models
#1

(This post was last modified: 06-12-2024, 09:36 AM by Anharr.)

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 ?
Reply
#2

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

(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"))
Reply
#4

(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 !
Reply




Theme © iAndrew 2016 - Forum software by © MyBB