In English, when you say to someone: "Have a good day!" you're not ordering them to have a good day, you are expressing a wish: "I hope you have ...." or "May you have ..."
When you wish someone a good day, etc. in Spanish, you are saying something similar:
"¡Que tengas un buen día!" (familiar) and "¡Que tenga un buen día!" (formal) both mean "[May you] have a good day!"
I hope that...
The verb form that is used in such wishes is the subjunctive mood. Look at the difference:
Tienes un buen día. - You are having a good day.
¡Que tengas un buen día! - Have a good day!
The combination "que+subjunctive" implies "may ..." or "I hope that ..."
Following are a few other common wishes in Spanish:
¡Que tengas una buena estancia! - Have a good stay!
¡Que tengas suerte! - Good luck! (May you have luck!)
¡Que tengas buen viaje! - Have a good trip!
¡Que te mejores! - Get well soon! (May you get better!)
¡Que (te) vaya bien! - Good luck (to you)! / I hope it goes well (for you)!
¡Que aproveche! - Enjoy your meal! (Spain)
Getting the feel for the context in which the subjunctive is used (rather than learning a bunch of rules) is a good way to start learning this verb form. ¡Que te vaya bien!