Here is a code snippet that will return 6 months from the previous day. It also takes into account years, so 6 months ago from January will return July of the previous year. I also added error handling for if the day of the month is greater than the number…