Get Month Name and Day name for a Date in C#, ASP.Net
Sometimes, we may need to get the full month name and day name in ASP.Net from a given date.
In this small article, we will achieve this by 2 ways,
- The ToString() method of DateTime will acccept the formatting string through which we can display the full month and day name for a given date.
Response.Write(DateTime.Now.ToString("MMMM")); Response.Write("<br>"); Response.Write(DateTime.Now.DayOfWeek);
- The next method is to use DateTimeFormatInfo class of System.Globalization namespace. This class has GetMonthName() and GetDayName() method which gives the full month name and day name.
DateTimeFormatInfo dinfo = new DateTimeFormatInfo(); Response.Write(dinfo.GetMonthName(12)); Response.Write(dinfo.GetDayName(DayOfWeek.Monday));
Include System.Globalization namespace for the above code to work.
Happy Coding!!
|