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
318 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

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