• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2137
  • Last Modified:

Datetime.Now without special characters?

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:
072907_125020PM

where I'm adding the underscore?
0
brettr
Asked:
brettr
3 Solutions
 
DarkoLordCommented:
DateTime.Now.ToString("MMddyyyy_hhmmtt")

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
0
 
Ted BouskillSenior Software DeveloperCommented:
You can format the string any way you want.

DateTime.Now.ToString("MMddyy_hhmmsstt");
0
 
DhaestCommented:
Did you look at the format-function ?
http://blog.stevex.net/index.php/string-formatting-in-csharp/

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now