Datetime.Now without special characters?

Posted on 2007-07-29
Last Modified: 2013-11-07
I'm using C# .NET 2.0.  Is there a method that will strip out slashes and colons from DateTime.Now so that 7/29/07 12:50:20 PM looks like:

where I'm adding the underscore?
Question by:brettr
    LVL 22

    Assisted Solution


    However note that the time will be displayed in 12 hour fourmat, however AM/PM designator will be added only where it is defined in the regional settings
    LVL 51

    Accepted Solution

    You can format the string any way you want.

    LVL 53

    Assisted Solution

    Did you look at the format-function ?

    MyDate = String.Format({0:ddMMyyyy_t,DateTime.Now())

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 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

    17 Experts available now in Live!

    Get 1:1 Help Now