+ Start a Discussion
andyaldis1.3969086903835708E12andyaldis1.3969086903835708E12 

Check if an Activity Date is in the current quarter

Hello,

I have to write a if statement that will check if the ActivityDate on a task is in the current quarter.  Does anyone have a quick trick on how I can do that?  I figure it has to be a pretty common formula.  
Best Answer chosen by andyaldis1.3969086903835708E12
TJ DTJ D
If you are looking for non-apex based solution then follow below article-
https://help.salesforce.com/articleView?id=000004173&type=1

If you need this in apex; you can try using period object. Below query gives you a start date and end date-
Date startDate = [Select startdate From Period Where type = 'Quarter' and StartDate = THIS_FISCAL_QUARTER].startdate;
Date endDate = [Select enddate From Period Where type = 'Quarter' and StartDate = THIS_FISCAL_QUARTER].enddate;
then use if statement to check-
if(ActivityDate > startDate && ActivityDate < endDate){
//your code here
}

Let me know if it works.

All Answers

TJ DTJ D
If you are looking for non-apex based solution then follow below article-
https://help.salesforce.com/articleView?id=000004173&type=1

If you need this in apex; you can try using period object. Below query gives you a start date and end date-
Date startDate = [Select startdate From Period Where type = 'Quarter' and StartDate = THIS_FISCAL_QUARTER].startdate;
Date endDate = [Select enddate From Period Where type = 'Quarter' and StartDate = THIS_FISCAL_QUARTER].enddate;
then use if statement to check-
if(ActivityDate > startDate && ActivityDate < endDate){
//your code here
}

Let me know if it works.
This was selected as the best answer
TJ DTJ D
Please mark the answer as best answer if it helped you to resolve the issue.