“Have a good day” is a very common American English expression. It is used in casual conversation between friends, acquaintances, and even strangers on a very regular basis.
The expression can be used at any time of day, although it makes more sense to use it earlier in the day, or at least before evening. However, if it is late afternoon or evening, one might say, “Have a good evening,” or “have a good night” instead. But there are no hard-and-fast rules as to when the phrase should be used.
As a more formal greeting, cashiers and people-greeters at retail stores are notorious for using the phrase when speaking to customers. It is meant as a pleasantry, or an automatic response, with the intent to make the clientele feel like they are cared about personally. A waitress also might use the phrase after you have paid for your meal and you are about to leave the restaurant. Other people who might say this phrase to you even if you do not know them personally include: a bank teller, a librarian, or a telephone operator.
The phrase is used among friends and acquaintances too. When you are speaking to someone you know, however, you might extend the phrase to make it more sincere. For instance, to your best friend you might say, “It was nice to see you. I hope you have a really nice day.” Or you could also say, “I hope that the rest of your day is good.”