(With 'in' the sentence is ungrammatical)
I have been to hospital this year.
(It means that you spent some time in hospital this year, taking a treatment course. Now you are back home).
I have been in hospital for two weeks.
(You have already spent 2 weeks in hospital, taking a treatment course, and are still there)
Student or Learner