You can visit the city any time of the year, but the ideal time to come is during the winter, which is from October until February. During this time period the weather will be significantly cooler, which means sightseeing will be much easier.
Summers are somewhat hot. However, during the rest of the year the city is also extremely popular, especially as a weekend getaway for the people in Bangalore. The summer time is the best time to come if you are looking to get a good deal on the hotel and other costs. This is when most of the people will come with their children and it is the off-season. The worst time to visit the city is during the monsoons because they typically receive heavy rain for days on end and it would be a waste of your time.