CSharp examples for System:DateTime Month
Return the number for the specified month from either the name or abbreviation.
using System.Collections; using System;// w w w . ja v a2 s.c o m public class Main{ #endregion #region -------- GET MONTH VALUES -------- /// <summary> /// Return the number for the specified month from either the name or abbreviation. /// </summary> /// <param name="month">The month name</param> /// <returns>The number of a given month</returns> public static string GetMonthNumber(string month) { if (month == null) return "0"; month = month.ToUpper(); int count = months.Count; for (int i = 0; i < count; i++) { if (((Month)months[i]).Name.ToUpper() == month) return Convert.ToString(((Month)months[i]).Number); if (((Month)months[i]).Abbreviation.ToUpper() == month) return Convert.ToString(((Month)months[i]).Number); } return null; } }