Showing posts with label Month Name in c#. Show all posts
Showing posts with label Month Name in c#. Show all posts

11 January 2022

How to get month number using month name in c#

 using System;


namespace ConsoleApp1

{

    public class How_to_get_month_number_using_month_name

    {

        public void getMonthNumber()

        {

            string  monthName = "feb";//February

            int monthNumber = Convert.ToDateTime("01-" + monthName + "-2011").Month;

            Console.WriteLine(monthNumber);  //Output: 2

        }

    }

}


How to get month name using month number in c#

using System;


namespace ConsoleApp1

{

    public class How_to_get_month_name_using_month_number

    {

        public void getMonthName()

        {

            int monthNumber = 2;

            DateTime date = new DateTime(2020, monthNumber, 1);

            string monthName = date.ToString("MMMM");

            Console.WriteLine(monthName);  //Output: February

        }

    }

}

 

Github Link: https://github.com/adi501/C-Sharp-Examples