It is narrated from Hazrat Abu Huraira (may Allah be pleased with him) that the Holy Prophet (peace and blessings be upon him) said: Whoever participates in a gathering and there is excessive frivolity, then when leaving that gathering, if he says: "Subhanaka Rabbana wa bihamdika la ilaha illa anta astaghfiruka thumma atubu ilaik," the sins committed in that gathering will be forgiven.
Hadith Referenceمسند احمد / مسند المكثرين من الصحابة / 10415