format string to remove day of week

Posted on 2009-05-01
Last Modified: 2012-05-06
I am using VS.NET 2003 and need to display date but dont want the day of the my string is currently....
Wednesday, April. 23, 2008
I created a case statement to check and truncate the month from April to Apr.
now i want to remove the day of the week, can I do this easier than doing a case statement and a replace, for each day of the week, looking for something with less code, perhaps an array type of idea...but not sure on how to go about that.

Wednesday, Apr. 23, 2008
Question by:solraccheffy
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    So something like below doesn't work for you?
    DateTime d = new DateTime(2009, 5, 1);
    d.ToString("MMM dd, yyyy")

    Open in new window


    Author Comment

    getting this error...
    Argument '1': cannot convert from 'string' to 'long'
    The best overloaded method match for 'System.DateTime.DateTime(long)' has some invalid arguments

    The string I am passing is "Wednesday, April 23, 2008" does not work in your example.

    DateTime newDate = new DateTime(FormattedDate);
    return newDate.ToString("MMM dd, yyyy");
    LVL 74

    Accepted Solution

    What about:
    Convert.ToDateTime("Wednesday, April 23, 2008").ToString("MMM dd, yyyy");

    Open in new window

    LVL 12

    Expert Comment

    Snippet to ponder

    String date = "Wednesday, Apr. 23, 2008";
      String parts = date.Split (",");
      date = parts[1]+","+parts[2];

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    Contant UI messages in .NET 1 17
    prevent lose focus 6 48
    reading json from C# REST service 1 27
    Handling arrays 14 28
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now