Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Month Name in c# (August)

Reply
Thread Tools

Month Name in c# (August)

 
 
sck10
Guest
Posts: n/a
 
      08-11-2006
Hello,

What I am trying to do is get the string(August) from:
hdnMonth.Value = DateTime.Now.Month.ToString();

Does c# have a function like the vb function "MonthName" ?
hdnMonth.Value = CType(MonthName(Month(Now())), String)

Thanks, sck10


 
Reply With Quote
 
 
 
 
Laurent Bugnion
Guest
Posts: n/a
 
      08-11-2006
Hi,

sck10 wrote:
> Hello,
>
> What I am trying to do is get the string(August) from:
> hdnMonth.Value = DateTime.Now.Month.ToString();
>
> Does c# have a function like the vb function "MonthName" ?
> hdnMonth.Value = CType(MonthName(Month(Now())), String)
>
> Thanks, sck10


You don't say in which culture, so I am going to assume you want it in
the current culture:

string monthName
= CultureInfo.CurrentCulture.DateTimeFormat.GetMonth (
DateTime.Now.Month );

Note that with GetMonth, 1 returns January and not 0 like you would have
expected.

Note also that GetMonth can accept 1 to 13, with 13 returning an empty
string.

http://msdn.microsoft.com/library/de...hnametopic.asp

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      08-11-2006
"sck10" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...


> What I am trying to do is get the string(August) from:
> hdnMonth.Value = DateTime.Now.Month.ToString();
>
> Does c# have a function like the vb function "MonthName" ?
> hdnMonth.Value = CType(MonthName(Month(Now())), String)


Easy as pie...

string strMonth = DateTime.Now.ToString("MMMM");


 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      08-14-2006
Thanks for Laurent and Mark's informative input.

Hi Steve,

As Mark has mentioned, as simple way to get the long month name of the date
is use the DateTime object ToString method and supply the "MMMM" format
string. Also, the below statement will only return the month name
associated with the current thread's CultureInfo

Response.Write("<br/>" + date.ToString("MMMM"));

if you want to return the culture-neutral (english) month name, you can
also supply the "InvariantCulture" formatter info.

Response.Write("<br/>" + date.ToString("MMMM",
CultureInfo.InvariantCulture));

Here are some useful info about common date/time formatting in .net
framework:

#Custom DateTime Format Strings
http://msdn.microsoft.com/library/en...omdatetimeform
atstrings.asp?frame=true

#Standard DateTime Format Strings
http://msdn.microsoft.com/library/en...darddatetimefo
rmatstrings.asp?frame=true

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
sck10
Guest
Posts: n/a
 
      08-14-2006
Hi Steven,

Thanks for the links. Appreciate it...


"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for Laurent and Mark's informative input.
>
> Hi Steve,
>
> As Mark has mentioned, as simple way to get the long month name of the
> date
> is use the DateTime object ToString method and supply the "MMMM" format
> string. Also, the below statement will only return the month name
> associated with the current thread's CultureInfo
>
> Response.Write("<br/>" + date.ToString("MMMM"));
>
> if you want to return the culture-neutral (english) month name, you can
> also supply the "InvariantCulture" formatter info.
>
> Response.Write("<br/>" + date.ToString("MMMM",
> CultureInfo.InvariantCulture));
>
> Here are some useful info about common date/time formatting in .net
> framework:
>
> #Custom DateTime Format Strings
> http://msdn.microsoft.com/library/en...omdatetimeform
> atstrings.asp?frame=true
>
> #Standard DateTime Format Strings
> http://msdn.microsoft.com/library/en...darddatetimefo
> rmatstrings.asp?frame=true
>
> Hope this also helps.
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
>
> ==================================================
>
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscripti...ult.aspx#notif
> ications.
>
>
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscripti...t/default.aspx.
>
> ==================================================
>
>
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>



 
Reply With Quote
 
kaverao kaverao is offline
Junior Member
Join Date: Sep 2009
Posts: 3
 
      09-24-2009
this code works for me. Thanks. CultureInfo.CurrentCulture.DateTimeFormat.MonthNam es.GetValue(InvoiceDate.Month ).ToString()
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Convert month name to month number faster Steven D'Aprano Python 0 01-06-2010 12:48 PM
RE: Convert month name to month number faster VYAS ASHISH M-NTB837 Python 0 01-06-2010 11:14 AM
VoIP - Sign up today & Receive 1 Month Free Plus a $5 credit each month BRight777 VOIP 0 08-05-2006 11:52 PM
Figure out month number from month abbrievation Bill Python 10 04-13-2006 12:36 PM
MonthCalendar1 or DateTimePicker1 How to jump for one month or haw to get no of month? Michal Maciejczak C++ 1 04-23-2005 11:18 AM



Advertisments