# std::chrono::month::ok

> C++ Atlas: `cppatlas.com/w/cpp/chrono/month/ok` | Source: https://en.cppreference.com/w/cpp/chrono/month/ok | Domain: Date and time utilities | Standards: C++20

Checks if the month value stored in *this is in the valid range, i.e., [1, 12].

## Official Specification Summary (cppreference)

```cpp
constexpr bool ok() const noexcept; // (since C++20)
```

Checks if the month value stored in `*this` is in the valid range, i.e., `[1,` `12]`.

### Return value

`true` if the month value stored in `*this` is in the range `[1,` `12]`. Otherwise `false`.

### Example

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

int main()
{
    for (const unsigned mm : {6u, 0u, 16U})
    {
        std::cout << mm << ": ";
        const std::chrono::month m{mm};
        m.ok() ? std::cout << "month is valid\n"
               : std::cout << "month is invalid\n";
    }
}
```

Output:

```text
6: month is valid
0: month is invalid
16: month is invalid
```

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