The Mexico City government’s guide for visitors advises a greeting “antes de hacer o decir algo, en cualquier entorno” (before doing or saying anything, in any setting). It is “Buenos días” before 11 a.m. and “Buenas tardes” until nightfall. The guide calls this “algo cultural” (something cultural).
The greeting comes before buying something, on entering an elevator, to taxi drivers, and before asking for directions.