tags:

views:

53

answers:

4

Can anybody tell me that how i can get current month and year and show it in a lable in asp.net

A: 

Use the DateTime.Now property. This returns a DateTime object that contains a Year and Month property (both are integers).

string currentMonth = DateTime.Now.Month.ToString();
string currentYear = DateTime.Now.Year.ToString();

monthLabel.Text = currentMonth;
yearLabel.Text = currentYear;
Rewinder
+1  A: 

Like this:

DateTime.Now.ToString("MMMM yyyy")

For more information, see DateTime Format Strings.

SLaks
A: 

label1.Text =DateTime.Now.Month.ToString();

and

label2.Text=DateTime.Now.Year.ToString();

anishmarokey
+1  A: 

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();
devil_coder