This is 14 Going on 30 (1988).
14 Going on 30 is a 1988 American made-for-television comedy film that was broadcast by American Broadcasting Company and Buena Vista Television and later distributed by Walt Disney Home Video. Directed by Paul Schneider, it stars Steven Eckholdt as Danny, a 14-year-old boy who is infatuated with his teacher Miss Peggy Noble (Daphne Ashbrook). Danny uses a "growth accelerator" to make himself appear older than his actual age in an attempt to seduce her.
The 14-year-old protagonist, Danny, is infatuated with his homeroom teacher, Miss Noble. He thinks she has feelings for him too, but panics when he learns that she's just gotten engaged to the physical education teacher, Coach Kelton. He attempts to convince her that Kelton isn't the right man for her, but is unsuccessful, which he puts down to him being too young for her to take his advice seriously.
Fortunately, he has a perfect solution in a device invented by his stereotypical, bespectacled science nerd friend, Lloyd. The device was designed to accelerate the growth of plants, with the aim of ending world hunger, but Danny uses it to age his body to the physical equivalent of 30 years old.
He then puts on some of his dad's clothes and goes to school, planning to tell Miss Noble that he's a relative of Coach Kelton, and that Kelton has a mental disorder that'll make him an unsuitable husband. When he arrives at the school though, he's mistaken for the new principal, Harold Forndexter -- who's assumed to have turned up a week early -- and decides to use that as his cover story instead. As a bonus, this enables him to institute various changes to the school rules to make education more fun for the students. Conveniently, his parents happen to be away while all this is going on.
Unsurprisingly, the students are thrilled about these changes, and Miss Noble approves of them too, noting that her students have never been happier in class or more eager to learn. She's also charmed by 'Harold Forndexter's' youthful optimism and open-mindedness. Conversely, Coach Kelton can't stand the new principal or the new, more irreverent school rules, as he's an old-fashioned type who believes in military-style discipline and order. He's basically the antagonist in this film.
Toward the end of the film, Miss Noble realises that Kelton isn't the right guy for her after all, and has fallen in love with 'Harold Forndexter' instead. However, Danny realises he can't keep up this charade forever, as his parents will soon be returning home. He speaks to Miss Noble as an adult one last time, to let her know that he has to go away and won't be able to return -- breaking her heart in the process -- and then goes to Lloyd's house and uses the machine to restore his body to its normal physical age.
When he attends his homeroom class the next day, the real Principal Forndexter is there, and he informs the students that Miss Noble has resigned, and that a new homeroom teacher will be arriving shortly. Danny is devastated, thinking that he's responsible for her resignation and that he'll never see her again. A new girl enters the class and sits down in the desk next to his, though, and he soon realises that Miss Noble discovered what he'd been up to with Lloyd's machine, and that she's now used the machine to turn herself into a teenager.
Lloyd also used the machine to turn himself into an adult, and shows up as the new homeroom teacher, 'Mr. Lloyd.' According to the IMDB credits for the film, 'Mr. Lloyd' is played by Sal Viscuso rather than Rick Moranis.