How to count the number of days in a specific month with C#

1 Answer

0 votes
using System;

class Program
{
    static void Main()
    {
        int year = 2025;
        int month = 2; // February

        int daysInMonth = DateTime.DaysInMonth(year, month);

        Console.WriteLine($"The number of days in {month}/{year} is: {daysInMonth}");
    }
}



/*
run:

The number of days in 2/2025 is: 28

*/







 



answered Aug 6, 2025 by avibootz
...