w3resource

C++ Date: Exercises, Practice, Solution

C++ Date [6 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.]

1. Write a C++ program to get the current date and time. Go to the editor
The current date and time is:
Tue Mar 15 14:28:05 2022
N.B.: The result may vary for your current system date and time.
Click me to see the sample solution

2. Write a C++ program to get the day of the week from a given date. Return the day as a string. The format of the given date is MM/DD/YYYY. Go to the editor
Date: 02/05/1980 Day of the week: Tuesday
Date: 01/24/1990 Day of the week: Wednesday
Date: 01/05/2019 Day of the week: Saturday
Date: 11/17/2022 Day of the week: Thursday
Click me to see the sample solution

3. Write a C++ program to convert a given year to century. Go to the editor
Year: 1900, Century of the year: 19
Year: 1999, Century of the year: 20
Year: 2000, Century of the year: 20
Year: 2010, Century of the year: 21
Year: 2020, Century of the year: 21
Click me to see the sample solution

4. Write a C++ program to check whether a given year is a leap year not. Go to the editor
Is Leap year: 1900? Century of the year: 0
Is Leap year: 1999? Century of the year: 0
Is Leap year: 2000? Century of the year: 1
Is Leap year: 2010? Century of the year: 0
Is Leap year: 2020? Century of the year: 1
Click me to see the sample solution

5. Write a C++ program to compute the number of days of a month from a given year and month. Go to the editor
Input Year: 2019
Input Month: 04
Number of days of the year 2019 and month 4 is: 30
Click me to see the sample solution

6. Write a C++ program to count the number of days between two given dates. Go to the editor
Date Format -> YYYY-MM-DD
Days between 2022/01/31 to 2022/01/01 = 30
Days between 2000/01/31 to 2019/02/01 = 6938
Days between 1980/05/31 to 1995/12/12 = 5677
Click me to see the sample solution

CPP Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.