You have turned for me my mourning into dancing; You have put off my sackcloth and clothed me with gladness, to the end that my glory may sing praise to You and not be silent. O LORD my God, I will give thanks to You forever.
Psalm 30 seems to describe a time of life-threatening illness that God saved David out of. In this prayer he praises God for his recovery in poetic terms, though David may have literally danced for joy and changed from the sackcloth of mourning to more festive clothing.
David’s main point, though, is his desire to always thank God for his deliverance—both physical and spiritual—forever.