We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    I’m querying on a table with a date field using the SQL year() funtion to filter records for a certain year.

    In my PHP the following code was used:
    $query = $modx->newQuery("Tariff");
    $query->where(array('year(date_from)' => $year));
    $tariffs = $modx->getCollection("Tariff", $query);
    


    xPDO generates the following where claue:
    WHERE `Tariff`.`year(date_from)` = '2010' 
    


    The $modx->getCollection call results in 0 objects, while there are actually records in the database with the queried year.

    When I run the query in phpmyadmin, it says:
    1054 - Unknown column 'Tariff.year(date_from)' in 'where clause'
    


    Am I doing something wrong?
      MODx Revolution / MAMP / OS X
      • 28215
      • 4,149 Posts
      splittingred Reply #2, 16 years ago
      $query->where(array(
        'YEAR(date_from) = '.$year,
      ));
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com