When my MIL visits (every few years), she routinely stays 3, 4, or even 5 months. I have a separate line item in my budget with her name on it, and I track all out-of-pocket expenses related directly to her (we pay for everything when she's here, including temporary gym membership for her to swim, presents for her to take back home to her friends, winter gear, etc.). I just budget for it and consider it a cost of "doing business" or rather, "having a family like my DH's!"
I am still struggling a bit with "spend as little as possible" vs. "spend on the important stuff," because family is the important stuff and I want my kids to know their grandparents. It helps to anticipate the expenses and budget in advance.