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
311 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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now