Forget Code launches a powerful code generator for building API's

Extracting month in a given date in C#

The code below extracts the month in a given date.

using System;

namespace forgetCode
    class Program
        static void Main(string[] args)

            Console.WriteLine("Enter year in the format dd-mm-yyyy");
            DateTime dt = Convert.ToDateTime(Console.ReadLine());

            //Know the month

            int month = dt.Month;

            Console.WriteLine("The month in the date you entered: "+month);


Enter year in the format dd-mm-yyyy
The month in the date you entered: 12