These two words get used interchangeably and they are not the same charge. Demurrage is what the port charges for your cargo occupying its yard beyond the free period. Detention is what the shipping line charges for its container being off its books beyond the free days in your contract.
They run on different clocks and they are billed by different parties. A consignment can be clear of demurrage and deep into detention, or the reverse.
Which is why we track the discharge date and the carrier’s free days on every consignment, and show them to you. A charge you can see coming is a charge you can usually avoid.