function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael MMichael M 

Date manipulation question

I need to do some date manipulation in Apex, as follows. I need to take today's date, get the 1st day of the  month (so for today, 9/1/20), and I need to return 4 months from that date (in this case, 1/1/21). 
So:
1. Get the first of THIS month
2. Get that date  + 4 months

Is there a way to do this with apex?

Best Answer chosen by Michael M
AbhishekAbhishek (Salesforce Developers) 
It can be achieved by using SOQL and formula in Apex.


I have some examples for you,

https://developer.salesforce.com/forums/?id=9060G000000BibSQAS

https://developer.salesforce.com/forums/?id=906F000000090RoIAI

https://stackoverflow.com/questions/9465900/how-do-we-get-the-first-and-last-day-of-the-current-month

https://developer.salesforce.com/forums/?id=906F0000000MN2wIAG

It will help your requirement.

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.

All Answers

AbhishekAbhishek (Salesforce Developers) 
It can be achieved by using SOQL and formula in Apex.


I have some examples for you,

https://developer.salesforce.com/forums/?id=9060G000000BibSQAS

https://developer.salesforce.com/forums/?id=906F000000090RoIAI

https://stackoverflow.com/questions/9465900/how-do-we-get-the-first-and-last-day-of-the-current-month

https://developer.salesforce.com/forums/?id=906F0000000MN2wIAG

It will help your requirement.

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
This was selected as the best answer
Michael MMichael M
Thank you!