কম্পিউটার টিউটোরিয়াল

C#-এ DateTime.DaysInMonth() মেথড

C#-এ DateTime.DaysInMonth() মেথডটি নির্দিষ্ট মাস এবং বছরের দিনের সংখ্যা রিটার্ন করতে ব্যবহৃত হয়। উদাহরণস্বরূপ, মাস মান ১ (অর্থাৎ জানুয়ারি) এর জন্য ৩১।

সিনট্যাক্স

public static int DaysInMonth (int year, int month);

উদাহরণ

using System; 
public class Demo { 
    public static void Main() { 
        DateTime date1 = new DateTime(2019, 08, 20, 6, 20, 40); 
        DateTime date2 = new DateTime(2019, 06, 20, 6, 20, 40); 
        Console.WriteLine("DateTime 1 = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", date1); 
        Console.WriteLine("Days in DateTime 1 month = " + DateTime.DaysInMonth(2019, 08)); 
        Console.WriteLine("\nDateTime 2 = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", date2); 
        Console.WriteLine("Days in DateTime 2 month = " + DateTime.DaysInMonth(2019, 06)); 
        int res = date1.CompareTo(date2); 
        // 1 রিটার্ন করে কারণ date1, date2-এর চেয়ে পরে 
        Console.WriteLine("\nReturn Value (comparison) = " + res); 
    } 
}

আউটপুট

DateTime 1 = 20 August 2019, 06:20:40 Days in DateTime 1 month = 31 DateTime 2 = 20 June 2019, 06:20:40 Days in DateTime 2 month = 30 Return Value (comparison) = 1

উদাহরণ: লিপ ইয়ার (Leap Year) চেক

using System; 
public class Demo { 
    public static void Main(){ 
        int year1 = 2019, year2 = 2016; 
        int FebMonth = 2; 
        Console.WriteLine("Days in 2019, Feb month = " + DateTime.DaysInMonth(year1, FebMonth)); 
        Console.WriteLine("Days in 2016, Feb month = " + DateTime.DaysInMonth(year2, FebMonth)); 
    } 
}

আউটপুট

Days in 2019, Feb month = 28 Days in 2016, Feb month = 29
  1. C#-এ DateTime.Subtract() মেথড: তারিখ বা টাইমস্প্যান বিয়োগ করা

  2. C#-এ DateTime.AddYears() পদ্ধতি

  3. C#-এ DateTime.AddHours() মেথড

  4. C#-এ DateTime.AddDays() মেথড