When you're young and in school memorizing math formulas or history dates or whatnot, all of it seems so silly and you wonder if you're really going to be using all of this knowledge in real life. However, the intent of a general education program isn't specifically to give you knowledge that will be useful to you in the future (although it may turn out to be so)
The stuff school teaches you -- literature, mathematics, art, history, science, and so on -- are intended to give you a broad enough base from which you can freely choose the direction you want to go in life. This means that as you specialize, many of these subjects may become "irrelevant" to you, but having this broad base of knowledge gives you a better foundation in life. Knowledge from unrelated fields can often give useful insight into your own specialized field
That being said, the most useful stuff you learn from school isn’t the stuff that’s in the lectures or in the textbooks. School is supposed to teach you about more than formulas and history dates too. But it's a problem that most of the time, formal education doesn't deliver the lessons well enough. Math shouldn't be about memorizing formulas or equations, but about developing analytical and problem solving skills. History should be about appreciating how changes affect people and societies, not about memorizing dates. Science should be about appreciating how nature works and developing scientific curiosity. And so on. But because these things are difficult to teach and test for, formal education usually focuses on facts and figures and formulas and all these things that appear in exams. It's up to the student (or his mentors encourage him) to apply himself further
There are still many more holes in formal education. There are memes about how you learn not so useful stuff like "mitochondria is the powerhouse of the cell" instead of real-world useful things like how to manage your finance or how to do your taxes. And for sure we need more of those practical things taught to students.
But the most important things you learn from school are in the methods of learning and working well with others. School teaches how to apply yourself, how to study and pick up new material, how to listen to other people, how to determine which knowledge is useful to learn, how to discern truth from fiction, how to work within a set of rules, how to manage your time, how to deal with schedules and deadlines, how to work well with other people, how to deal with difficult people, and so on. In short, the most important lessons school teaches you are about how to deal with the real world