- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to display the number of days in a month
Use the DaysInMonth to display the number of days in a month.
Add the year and month as a parameter for the DaysInMonth() method −
DateTime.DaysInMonth(2018, 8);
The following is an example −
Example
using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { Console.WriteLine("Today = {0}", DateTime.Today); int num_days = DateTime.DaysInMonth(2018, 8); Console.WriteLine("Days in August: "+num_days); } }
Output
Today = 9/4/2018 12:00:00 AM Days in August: 31
Advertisements
To Continue Learning Please Login
Login with Google