Yeah it's the same in Spanish. You have to use "Buenos días" if you're in the morning,"Buenas Tardes"tardes" for the afternoon/evening and "Buenas noches" at night.
It's difficult to say when you have to stop saying "Buenos días" and start saying "Buenas Tardes"tardes". Literally, the point would be at noon, but at least in Spain people say "Buenos días" before having lunch and "Buenas Tardestardes after that point" (Spanish people have lunch around 2 pm or so). The change between "Buenos días""Buenas tardes" and "Buenas noches" would be in the sunset but the change could also be done at dinner time.
But if you say "Buenos días" at 6pm it would be definitely strange.