Help - Search - Members - Calendar
Full Version: Selecting Records From Two Timestamps
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Turv
CODE
    function callbacks() {
    
        $q = "SELECT     contact_info.contact_id,
                        contact_info.company_name,
                        contact_info.contact_name,
                        contact_info.contact_pcs,
                        contact_info.contact_phone,
                        contact_info.contact_postcode,
                        contact_status.status,
                        contacts.nextaction
            FROM        contact_info
            INNER JOIN    contacts
            ON            contact_info.contact_id = contacts.id
            INNER JOIN    contact_status
            ON            contact_status.status_id = contacts.status_id
            WHERE        (TO_DAYS(contacts.nextaction)) - TO_DAYS(NOW()) <= 1
            AND            contacts.user_id = 1
            LIMIT        50";
            
        $query = $this->db->query($q);        
        return $query->result_array();
    }


Okay, What i am trying to do is Select all the records before Todays date, The database has a field (nextaction) that stores a timestamp and i am trying to query the database to pull all of the records where the timestamp is before now.

Now if i put an actual timestamp in the WHERE Caluse, such as..
CODE
WHERE    (TO_DAYS(11211134554)) - TO_DAYS(NOW()) <= 1


This returns all the records it should do, although if i try and reference it with the timestamp pulled from the database (contacts.nextaction) it returns no results.

If someone has a better, or a working method of doing the above then i would appreciate any advice you can offer.

Regards,
Ed
Try DATE_SUB, something similar to:

SQL
SELECT foo FROM bar WHERE nextaction < DATE_SUB(NOW(), INTERVAL 1 DAY)


Worth noting:
For this to work your nextaction column type should be datetime
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.