Round Date to closest month

Hi friends,

Looking to round up/down a date to the nearest month ( > 15). Would be great if it could also round up to the next year if it was, lets say 12/25/2019 to January 2020.

Any ideas?

Thanks in advance for your time!

Hi @efleurent,

You can use .AddMonths(num) method to do this. Let’s say you have var1 which have 12/25/2019. Use **var1.Date;**it will return you the date .To store date in integer variable let say date1 . Now if date1>15 then var1.AddMonths(1) else var1.AddMonths(-1).

Hope it helps.

Best!!
Anmol

1 Like

clever solution! Worked perfectly. Thanks a lot @anmolk171 :slight_smile:

1 Like

No worries. Happy Learning.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.