Month Name in c# (August)

Discussion in 'ASP .Net' started by sck10, Aug 11, 2006.

  1. sck10

    sck10 Guest

    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
     
    sck10, Aug 11, 2006
    #1
    1. Advertising

  2. 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/d...ndatetimeformatinfoclassgetmonthnametopic.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
     
    Laurent Bugnion, Aug 11, 2006
    #2
    1. Advertising

  3. sck10

    Mark Rae Guest

    "sck10" <> wrote in message
    news:...


    > 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");
     
    Mark Rae, Aug 11, 2006
    #3
  4. 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-us/cpguide/html/cpconcustomdatetimeform
    atstrings.asp?frame=true

    #Standard DateTime Format Strings
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconstandarddatetimefo
    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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

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



    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Aug 14, 2006
    #4
  5. sck10

    sck10 Guest

    Hi Steven,

    Thanks for the links. Appreciate it...


    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > 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-us/cpguide/html/cpconcustomdatetimeform
    > atstrings.asp?frame=true
    >
    > #Standard DateTime Format Strings
    > http://msdn.microsoft.com/library/en-us/cpguide/html/cpconstandarddatetimefo
    > 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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
     
    sck10, Aug 14, 2006
    #5
  6. sck10

    kaverao

    Joined:
    Sep 17, 2009
    Messages:
    3
    CultureInfo.CurrentCulture.DateTimeFormat.MonthNam es.GetValue(InvoiceDate.Month )

    this code works for me. Thanks. CultureInfo.CurrentCulture.DateTimeFormat.MonthNames.GetValue(InvoiceDate.Month ).ToString()
     
    kaverao, Sep 24, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laura Creighton

    pyweek is happening august 02 - august 09

    Laura Creighton, Aug 4, 2007, in forum: Python
    Replies:
    0
    Views:
    570
    Laura Creighton
    Aug 4, 2007
  2. Luke Paireepinart
    Replies:
    0
    Views:
    587
    Luke Paireepinart
    Aug 4, 2007
  3. Laura Creighton
    Replies:
    0
    Views:
    571
    Laura Creighton
    Aug 5, 2007
  4. John Pinner
    Replies:
    0
    Views:
    571
    John Pinner
    Aug 5, 2007
  5. VYAS ASHISH M-NTB837

    RE: Convert month name to month number faster

    VYAS ASHISH M-NTB837, Jan 6, 2010, in forum: Python
    Replies:
    0
    Views:
    637
    VYAS ASHISH M-NTB837
    Jan 6, 2010
Loading...

Share This Page