You're thinking of 17 Again, with Matthew Perry and Zac Effron both playing the character Mike O'Donnell at different ages. It isn't a time travel movies, though. It starts when Mike is 17 years old and abandons his hopes of a basketball career when he and his girlfriend become pregnant. (I say both are pregnant because it's a convention of parenthood, not because he's literally pregnant.) Through a weird series of Capraesque events, the older Mike suddenly and magically reverts to his 17-year-old body later in life and so has a chance to replay some of the events of his youth. The moral of the story is that he learns to be satisfied with the choices he already made, not go back to fix mistakes.

