Specifically, this phrase appears in Ecclesiastes 3:4 which reads:
"A time to weep, and a time to laugh; a time to mourn, and a time to dance."
This verse is part of a larger passage that explores the cyclical nature of life and the inevitability of both joy and sorrow.