Can anybody tell me that how I can get current month and year and show it in a label in ASP.NET?
using System.Globalization;
LblMonth.Text = DateTime.Now.Month.ToString();
DateTimeFormatInfo dinfo = new DateTimeFormatInfo();
int month = Convert.ToInt16(LblMonth.Text);
LblMonth.Text = dinfo.GetMonthName(month);
If you have following two labels:
<asp:Label ID="MonthLabel" runat="server" />
<asp:Label ID="YearLabel" runat="server" />
Than you can use following code just need to set the Text Property for these labels like:
MonthLabel.Text = DateTime.Now.Month.ToString();
YearLabel.Text = DateTime.Now.Year.ToString();