Print Page | Close Window

Dates

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=1769
Printed Date: 28 March 2026 at 2:24am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Dates
Posted By: karp13
Subject: Dates
Date Posted: 11 April 2003 at 1:28pm

How would you show the current month name in a label control.  I also need to show last month and 2 months ago. 3 different controls.

I know it has to be easy, but I just can't seem to figure it out for .net.

Thanks for the help

Karp13




Replies:
Posted By: xdotnet
Date Posted: 11 April 2003 at 1:52pm

use MonthName with Now.Month:

lblThisMonthName.Text = MonthName(Now.Month)

lblLastMonthName.Text = MonthName(Now.Month - 1)



Posted By: karp13
Date Posted: 11 April 2003 at 2:07pm

That's great! Thank You

Where can I find this information?  I would like to learn more about date formatting and such. 



Posted By: xdotnet
Date Posted: 11 April 2003 at 3:17pm

the code i give you is old VB, forget it, it's not a good practice with asp.net. this one is for asp.net:

lblThisMonthName.Text = Now.ToString("MMMM")
lblLastMonthName.Text = Now.AddMonths(-1).ToString("MMMM")

here is 2 links to get some infos about date formatting

DateTimeFormatInfo Class:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclasstopic.asp


DateTimeFormatInfo.MonthNames Property:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclassmonthnamestopic.asp - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationdatetimeformatinfoclassmonthnamestopic.asp


Also you can download the "Class Browser" who come for free with web matrix where you can get properties, methods etc... for each class.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net