Format DateTime in the form: "W E D N E S D A Y   9/11"

Posted on 2008-11-19
Last Modified: 2012-05-05
I am using .NET/C#. I have DateTime values I'm pulling from a DB. For a given DateTime value, I want the day formatted with a space between each letter of the day. Then I want two spaces, then I want a numeric month and day divided by a slash. Examples:

"W E D N E S D A Y   9/11"
"F R I D A Y   9/13"

The spacing on the lettering should ideally be done with StringBuilder or whatever so this doesn't suffer massive perf issues.

I'm sure I could hack this out myself but one of you geniuses know this straight off the top of your head, hmm?

Thanks much for any help you can offer.
Question by:kennethfine
    1 Comment
    LVL 12

    Accepted Solution

    Well this is what I can come up with.
    DateTime time = DateTime.Today;
    			string monthAndDate = time.ToString("MM/dd");
    			string day = time.DayOfWeek.ToString();
    			char[] arr = day.ToCharArray();
    			day = string.Empty;		
    			foreach (char c in arr)
    				day = string.Concat(day, c.ToString(), " ");
    			Console.WriteLine(string.Concat(day, " ", monthAndDate));

    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

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
    A Change in PHP Behavior with Session Write Short Circuit ( (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

    760 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

    15 Experts available now in Live!

    Get 1:1 Help Now