This method returns the month for the date given. - CSharp System

CSharp examples for System:DateTime Month

Description

This method returns the month for the date given.

Demo Code


using System.IO;//from  www  .j av a 2s. c om
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{
        #endregion
   
            #region GetTwoDigitMonth(DateTime date)
            /// <summary>
            /// This method returns the month for the date given.
            /// </summary>
            /// <param name="date"></param>
            /// <returns></returns>
            public static string GetTwoDigitMonth(DateTime date)
            {
                // initial value
                string twoDigitMonth = "";

                // set the twoDigitMonth
                twoDigitMonth = date.Month.ToString();

                // if the Length is less than two
                if (twoDigitMonth.Length < 2)
                {
                    // prepend a zero to the month
                    twoDigitMonth = "0" + date.Month.ToString();
                }

                // return value
                return twoDigitMonth;
            }
}

Related Tutorials