# std::chrono::duration<Rep,Period>::operator+=, -=, *=, /=, %=

> C++ Atlas: `cppatlas.com/w/cpp/chrono/duration/operator_arith3` | Source: https://en.cppreference.com/w/cpp/chrono/duration/operator_arith3 | Domain: Date and time utilities | Standards: C++11, C++17

Performs compound assignments between two durations with the same period or between a duration and a tick count value.

## Official Specification Summary (cppreference)

```cpp
duration& operator+=( const duration& d ); // (1) (since C++11) (constexpr since C++17)
duration& operator-=( const duration& d ); // (2) (since C++11) (constexpr since C++17)
duration& operator*=( const rep& rhs ); // (3) (since C++11) (constexpr since C++17)
duration& operator/=( const rep& rhs ); // (4) (since C++11) (constexpr since C++17)
duration& operator%=( const rep& rhs ); // (5) (since C++11) (constexpr since C++17)
duration& operator%=( const duration& rhs ); // (6) (since C++11) (constexpr since C++17)
```

Performs compound assignments between two durations with the same period or between a duration and a tick count value.

If `rep_` is the member variable holding the number of ticks in this duration object,

1) Equivalent to `rep_ += d.count(); return *this;`.

2) Equivalent to `rep_ -= d.count(); return *this;`.

3) Equivalent to `rep_ *= rhs; return *this;`.

4) Equivalent to `rep_ /= rhs; return *this;`.

5) Equivalent to `rep_ %= rhs; return *this;`.

6) Equivalent to `rep_ %= d.count(); return *this;`.

### Parameters

- `d` - duration on the right-hand side of the operator
- `rhs` - number of ticks on the right-hand side of the operator

### Return value

A reference to this duration after modification.

### Example

```cpp
#include <chrono>
#include <iostream>

int main()
{
    std::chrono::minutes m(11);
    m *= 2;
    m += std::chrono::hours(10); // hours implicitly convert to minutes
    std::cout << m.count() << " minutes equals "
              << std::chrono::duration_cast<std::chrono::hours>(m).count()
              << " hours and ";
    m %= std::chrono::hours(1);
    std::cout << m.count() << " minutes\n";
}
```

Output:

```text
622 minutes equals 10 hours and 22 minutes
```

### See also

- [`operator++`](https://en.cppreference.com/w/cpp/chrono/duration/operator_arith2), [`operator++(int)`](https://en.cppreference.com/w/cpp/chrono/duration/operator_arith2), [`operator--`](https://en.cppreference.com/w/cpp/chrono/duration/operator_arith2), [`operator--(int)`](https://en.cppreference.com/w/cpp/chrono/duration/operator_arith2): increments or decrements the tick count (public member function)
- [`operator+`](https://en.cppreference.com/w/cpp/chrono/duration/operator_arith4) (C++11), [`operator-`](https://en.cppreference.com/w/cpp/chrono/duration/operator_arith4), [`operator*`](https://en.cppreference.com/w/cpp/chrono/duration/operator_arith4), [`operator/`](https://en.cppreference.com/w/cpp/chrono/duration/operator_arith4), [`operator%`](https://en.cppreference.com/w/cpp/chrono/duration/operator_arith4): implements arithmetic operations with durations as arguments (function template)

---
Attribution: content from https://en.cppreference.com/w/cpp/chrono/duration/operator_arith3 (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.