VOOZH about

URL: https://www.geeksforgeeks.org/cpp/std-chrono-day-in-cpp-20/

⇱ std::chrono::day in C++ 20 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::chrono::day in C++ 20

Last Updated : 23 Jul, 2025

In C++, the <ctime> header provides the std::chrono::day class that represents a day in the given month. In this article, we will learn how to use the std::chrono::day class in C++.

std::chrono::day in C++

The ::day class was introduced in C++ 20 to represent a day in a month. It is a duration-based representation of the day in the calendar month. It allows for the precise calculations and manipulations of the dates and time durations. It is particularly useful when dealing with calendar-related operations and when precise handling of the time intervals is required.

Syntax of std::chrono::day

std::chrono::day d{day_count};

where:

  • day_count: An integer representing the day of the month ranging from 1 to 31.
  • Return Value: std::chrono::day object representing the specified day of the month.

Except for increment, equality and output operator overload, the std::chrono::day only have one member function named ok() which checks whether the value of the day object is in the valid range.

Example of std::chrono::day in C++

The following program illustrates how to use std::chrono::day in C++:


Output

Day of the month:-
Today: 4
Tommorow: 5

Time Complexity: O(1)
Auxiliary Space: O(1)

Explanation: The above program fetches the current date and extracts the day of the month from it using the std::chrono::day class.

Note: This program will only work in C++ 20 or above versions.

Comment
Article Tags: