month and year problem in asp.net

Posted by Suneel161 under Regular Expressions on 4/16/2010 | Views : 2001 | Status : [Member] | Replies : 6
How to get only month name and year in a label(like april 2010) in asp.net




Responses

Posted by: Deysomnath on: 4/16/2010 [Member] Starter

Up
0
Down
Try this..

Response.Write(DateTime.Now.ToString("MMM , yyyy"));

OUTPUT
---------------
Apr , 2010

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Atal.upadhyay on: 4/16/2010 [Member] Starter

Up
0
Down
Try with DateTime.Now.ToString("MMMM, yyyy");

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 4/17/2010 [Member] Bronze

Up
0
Down


Try This

DateTime.Now.ToString("MMMM yyyy")

the Oup Put will be as "April 2010"


Thanks
Pavan Kumar
Mark Answer if this fits the need

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sathya4260 on: 1/9/2011 [Member] Starter | Points: 25

Up
0
Down
DateTime.Now.ToString("MMMM/yyyy")

Sathish Kumar S

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/9/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down

Hi,

Hope the below code is your requirement.

<asp:Label ID="MonthLabel" runat="server" />

<asp:Label ID="YearLabel" runat="server" />

MonthLabel.Text = DateTime.Now.Month.ToString();
YearLabel.Text = DateTime.Now.Year.ToString();



Thanks
Karthik
www.f5Debug.net

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Suresh.mekkattil on: 1/9/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Pease try this;

string date = string.Format("{0:MMM yyyy}", DateTime.Now);
you can try with different ombinations like;

{0:dd MMM yyyy} For 12 January 2011
{0:dd MM yyyy} For 12 Jan 2011 etc.....

-----
Suresh M

Suneel161, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response