Top 30 C++ programming questions on the topic Date


Q 1. Write a C++ program to display the current date and time.

Expected Output:

The current date and time is: Tue Sep 6 08:21:04 2024

Q 2. Create a structure named Date with three members: day, month, and year. Write a program to input and display a date using this structure.

Expected Output:

Enter day: 6

Enter month: 9

Enter year: 2024

The date is: 6/9/2024

Q 3. Write a program to check whether a given year is a leap year or not.

Expected Output:

Enter a year: 2024

2024 is a leap year.

Q 4. Write a program to input a month (1-12) and a year, then display the number of days in that month.

Expected Output:

Enter month (1-12): 2

Enter year: 2024

February 2024 has 29 days.

Q 5. Write a program to find the difference in days between two dates.

Expected Output:

Enter first date (day month year): 6 9 2024

Enter second date (day month year): 1 1 2024

Difference: 249 days

Q 6. Write a program to find the day of the week for a given date.

Expected Output:

Enter date (day month year): 6 9 2024

The day is: Friday

Q 7. Write a program to increment a given date by one day.

Expected Output:

Enter date (day month year): 6 9 2024

Next date is: 7/9/2024

Q 8. Write a program to decrement a given date by one day.

Expected Output:

Enter date (day month year): 6 9 2024

Previous date is: 5/9/2024

Q 9. Write a program to calculate the number of days remaining until your next birthday.

Expected Output:

Enter your birthday (day month): 25 12

Days until your next birthday: 110

Q 10. Write a program to validate if the entered date is valid or not.

Expected Output:

Enter date (day month year): 31 2 2024

The date is invalid.

Q 11. Write a program to calculate the number of days between two given dates.

Expected Output:

Enter first date (day month year): 1 1 2024

Enter second date (day month year): 6 9 2024

Number of days between the dates: 249 days

Q 12. Write a program to display the date one week from today.

Expected Output:

Enter today's date (day month year): 6 9 2024

The date one week from today is: 13/9/2024

Q 13. Write a program to display the date one week before today.

Expected Output:

Enter today's date (day month year): 6 9 2024

The date one week before today is: 30/8/2024

Q 14. Write a program to display the date after a given number of days from today.

Expected Output:

Enter today's date (day month year): 6 9 2024

Enter number of days to add: 20

The date after 20 days is: 26/9/2024

Q 15. Write a program to display the date before a given number of days from today.

Expected Output:

Enter today's date (day month year): 6 9 2024

Enter number of days to subtract: 10

The date before 10 days is: 27/8/2024

Q 16. Write a program to find the day of the week for a given date.

Expected Output:

Enter date (day month year): 6 9 2024

The day of the week is: Friday

Q 17. Write a program to display a given date in words (e.g., 6th September 2024).

Expected Output:

Enter date (day month year): 6 9 2024

6th September 2024

Q 18. Write a program to add a certain number of months to a given date.

Expected Output:

Enter today's date (day month year): 6 9 2024

Enter number of months to add: 5

The date after adding 5 months is: 6/2/2025

Q 19. Write a program to subtract a certain number of months from a given date.

Expected Output:

Enter today's date (day month year): 6 9 2024

Enter number of months to subtract: 5

The date after subtracting 5 months is: 6/4/2024

Q 20. Write a program to display the number of days in a given month of a particular year.

Expected Output:

Enter month and year: 2 2024

Number of days in the month: 29

Q 21. Write a program to calculate the number of full months between two given dates.

Expected Output:

Enter first date (day month year): 6 9 2024

Enter second date (day month year): 6 12 2025

Difference in months: 15

Q 22. Write a program to add a certain number of years to a given date.

Expected Output:

Enter today's date (day month year): 6 9 2024

Enter number of years to add: 5

The date after adding 5 years is: 6/9/2029

Q 23. Write a program to subtract a certain number of years from a given date.

Expected Output:

Enter today's date (day month year): 6 9 2024

Enter number of years to subtract: 3

The date after subtracting 3 years is: 6/9/2021

Q 24. Write a program to find the last day of a given month.

Expected Output:

Enter month and year: 2 2024

Last day of the month: 29

Q 25. Write a program to determine if a given year is a leap year and the number of days in that year.

Expected Output:

Enter year: 2024

2024 is a leap year with 366 days.

Q 26. Write a program to determine which day of the year a given date falls on.

Expected Output:

Enter date (day month year): 6 9 2024

Day of the year: 250

Q 27. Write a program to calculate the number of days remaining in the current year from a given date.

Expected Output:

Enter date (day month year): 6 9 2024

Days remaining in the year: 116

Q 28. Write a program to print all the dates of a given month and year.

Expected Output:

Enter month and year: 9 2024

1/9/2024

2/9/2024

...

30/9/2024

Q 29. Write a program to find the date of the last Sunday before a given date.

Expected Output:

Enter date (day month year): 6 9 2024

Last Sunday was: 1/9/2024

Q 30. Write a program to check if a given date is valid or not.

Expected Output:

Enter date (day month year): 29 2 2024

The date is valid.

Social Share

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!

Programming Languages