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
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

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 30

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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