Detect month according to date selected?
I have two label in webform Label1 and Label2
Label1 displays the date as 1-Apr-2011
I want to display month as April in Label2 if date in label1 is in bet开发者_StackOverflow社区ween 1 to 30 Apr 2011.
I want to display month as May in Label2 if date in label1 is in between 1 to 30 May 2011.
If you are using C# you can try this:
Label2.Text = DateTime.Parse(lable1.text).ToString("M")
To get current month name in VB.net
Today.ToString("MMMM")
and in C#.net
DateTime.Now.ToString("MMMM");
Parse the text in Label1
into a DateTime
object and get the Month
property from that. Because this property is an int
you can then use an enum for the translation to a month.
Public Enum MonthsInYear
January = 1
February = 2
//...
End Enum
Dim month As DateTime = DateTime.Parse(Label1.Text)
Label2.Text = Enum.GetName(typeof(MonthsInYear), month)
See the MSDN page on parse-method for further information.
精彩评论