In AmE, I believe "I spent two months in the hospital".
I am going to make a rather far-fetched argument for using "at", in BrE at least. We generally say we are "at hospital" when we are there waiting to be admitted, or just there for a minor issue. "In hospital" suggests we have been admitted formally to the hospital and are actually taking up a hospital bed.
I was at [the] hospital for seven hours last night, after cutting my finger very badly.
I spent seven hours at the local hospital last night, after cutting my finger very badly.
The National Health Service is, for now, holding its own but it's just possible that one day things might slide to the point that I have to wait in the waiting room for two months before being seen. If that happens, then "I spent two months at the hospital before I was finally seen by a doctor!" As I said, it's very far-fetched but it might help you with the usage. The normal usage would be "I spent two months in hospital before the doctors decided I was well enough to be discharged".