You need to sign in to do that
Don't have an account?
degmo
Get same day of next year in Apex
Hi,
I need to add 1 year to date but the new date needs to fall in same day of week. For example, if my starting date is Saturday 7/24/2021, I want the new date to be Saturday 7/23/2022. If I do .addYears(1), I am getting 7/24/2022 which is a Sunday. Any suggestions?
I need to add 1 year to date but the new date needs to fall in same day of week. For example, if my starting date is Saturday 7/24/2021, I want the new date to be Saturday 7/23/2022. If I do .addYears(1), I am getting 7/24/2022 which is a Sunday. Any suggestions?
Hi Degmo,
Did you try using the function "Year". Please try something like below :-
Year(Date field) + 1
please let me know if it meet your need.
regards,
Priya Ranjan
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
Hi,
Please find the solution.
I think the below code is working fine if any changes are required, please do some need full changes.
Please mark it as the Best Answer so that other people would take references from it.
Thank You
@suraj,
your code is on the right path but it's flawed some. If I pass in a date 7/25/2021, I get 7/31/2022. But what I need is 7/24/2022.