sraje
sraje

Reputation: 134

How to specify a date range in SugarCRM's SugarQuery

I am trying to build a custom API in SugarCRM. To query the database, I am making use of the SugarQuery class. However I cannot find a method in the documentation that will enable me to specify a date range in the query.

My current code looks like this:

    $opportunity = BeanFactory::newBean('Opportunities');
    $opportunityQuery = new SugarQuery();
    $opportunityQuery->from($opportunity);
    $teamAlias = $opportunityQuery->join('teams')->joinName();
    $userAlias = $opportunityQuery->join('users')->joinName();
    $opportunityQuery->select($userAlias.'.id');
    $opportunityQuery->select($userAlias.'.user_name');
    $opportunityQuery->select->fieldRaw("COUNT(id)", 'opportunity_count');
    $opportunityQuery->groupBy($userAlias.'.id');
    $opportunityQuery->where()->in('sales_stage', array('Closed Won', 'Terminated'));
    /* Some thing like
    $opportunityQuery->where()->between('date_closed', array('NOW()', '2015-06-22'));*/
    $opportunities = $opportunityQuery->execute();
    return $opportunities;

Can anyone help out please....

Upvotes: 0

Views: 1007

Answers (2)

Rahul Kumar Gupta
Rahul Kumar Gupta

Reputation: 25

I suggest you to please follow SugarCRM Documentation : sugarcmr documentation

$SugarQuery->where()->dateBetween('date_created',array('2016-01-01','2016-03-01')); 

Upvotes: 0

Cédric Mourizard
Cédric Mourizard

Reputation: 576

Did you try to replace between by dateBetween?

Upvotes: 1

Related Questions