Japanese say this greeting when they leave work, school, sports practice, and at like doctors offices/hospitals etc. It is like saying goodbye, but you add a twist that would kind of be like “thank you for working hard together, goodbye”. It is maybe kinda like one of those Japanese group bonding things and difficult to explain in English cause there is nothing like it (maybe).

Not something to be said to family members or regular friends.

O’tsukaresama deshita is a formal way to say this, but there are other ways and notice the similarities between the words as they go from polite and formal (like what you would say to a boss, but never to a friend) to casual (what you would say to a workmate) and downright rude (what you would say to a friend, but NEVER say to your boss).

o’tsukaresama deshita (or o'tsukaresama desu)
o’tsukaresama
o’tsukare
tsukare
o’tsu