Solved

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?

Posted on 2013-11-06
2
320 Views
Last Modified: 2013-11-06
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]
0
Comment
Question by:zimmer9
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39628290
Sure...
string filenm = "HARRIS.HARRIS.PAECN10.PAECN10." + DateTime.Now.ToString("yyyyMMdd.hhmmss");

Open in new window


See "Custom Date and Time Format Strings":
http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
...for more info.

*If you want a 24 hour format, change "hh" to "HH".
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 39628305
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

809 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