Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

How would you to get a variable named "filenm" to be assigned a value with the trailing value of YYYYMMDD.HHMMSS in a C# console application?

I am developing a C# console application using VS2010.

Do you know how I could get a variable named "filenm" to be assigned the value:

HARRIS.HARRIS.PAECN10.PAECN10.YYYYMMDD.HHMMMSS    such that

YYYYMMDD would be replaced with the: 4 digit year + 2 digit month + 2 digit date of month

HHMMSS would be replaced with the [hours, minutes, seconds]
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Convert current date to string using the following format string (casing is important!):

            string dt = DateTime.Now.ToString("yyyyMMdd.HHmmss");
            System.Diagnostics.Debug.WriteLine(dt);

Open in new window


Output is like:

20131107.081854

Hours "HH" should be capital because it will print in 24-hours format. "hh"  prints in 12-hours format.