We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31640
    • 100 Posts
    Hi

    I am creating a module to maintain serial numbers.
    In the module there is a posibility to filter on creationuser and creationdate
    Now i want to query my custom table with a specific date but i don't succeed to create a where clause filtering that date.

    The creation date is defined like this:
    'creationdate' => 
        array (
          'dbtype' => 'timestamp',
          'phptype' => 'timestamp',
          'null' => false,
          'default' => 'CURRENT_TIMESTAMP',    
    


    My code is using a modObjectGetListProcessor to retreive the data.
    This is the get data method:

        public function getData() {
    
            $isLimit = !empty($scriptProperties['limit']);
            $start = $this->getProperty('start');
            $limit = $this->getProperty('limit');
            $sort = $this->getProperty('sort');
            $dir = $this->getProperty('dir');
            $query = $this->getProperty('query');
            $isLimit = !empty($limit);
    
            $searchitem = $this->getProperty('searchitem',false);
            $searchtype = $this->getProperty('searchtype',false);
            $searchdate = $this->getProperty('searchdate',false);
    
            $data = array();
    
            /* build query */
            $c = $this->modx->newQuery('Activation');
            $c ->select('Activation.*, Manufacturer.name as manufacturername, Location.region, Location.city, Location.postalcode, Location.street, Location.number');
            $c ->leftJoin('Location', 'Location', array('Activation.location = Location.id'));
            $c ->leftJoin('Manufacturer', 'Manufacturer', array('Activation.manufacturer = Manufacturer.id'));
    
            if (!empty($searchitem) && !empty($searchtype)) {
                switch ($searchtype) {
                    case "manufacturername":
                        $c->where(array('Activation.confirmed' => 1, 'Manufacturer.name' => $searchitem));
                        break;
                    default:
                        $c->where(array('Activation.confirmed' => 1, 'Activation.'.$searchtype => $searchitem));
                        break;
                }
            } else {
                $c->where(array('Activation.confirmed' => 1));
            }
    
            $data['total'] = $this->modx->getCount('Activation',$c);
    
            $c->sortby($this->getProperty('sort'),$this->getProperty('dir'));
            $c->sortby('serial','DESC');
            if ($isLimit) $c->limit($limit,$this->getProperty('start'));
    
            $data['results'] = $this->modx->getIterator('Activation',$c);
    
            return $data;
        }
    


    So what i want is a where clause where i can say: "Activation.creationdate => $searchdate"
    One remark. The creation date is defined as a current_timestamp (so with hour and minutes) the date to filter on is just having the date...

    Hopefully somebody can help

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      the time must be something between the daystart of the date in query and the daystart of the next day in query.
      So, does something like that work for you?

      $thisdaystart = strtotime(strftime('%Y-%m-%d',$date) );
      $nextdaystart = strtotime(strftime('%Y-%m-%d',$date + 24 * 60 *60));
      
      $c->where(array('creationdate:>='=>$thisdaystart,'creationdate:<'=>$nextdaystart));
      


      make sure $date is the unixtime of the date

      [ed. note: Bruno17 last edited this post 13 years, 8 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 31640
        • 100 Posts
        Thanks, this was completely the answer i was looking for!!!
        You saved my day smiley