[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

C# Format Date Time

Posted on 2013-01-14
3
Medium Priority
?
749 Views
Last Modified: 2013-01-19
This is prob an easy question but I am having issue.  I need to print date time in the following format.

Input -> Date Jan 14, 2013 Time 1:02 pm

Output -> 20130114 1302

I used below but it just prints

yyyyMMddHHmm

string.Format("yyyy", DateTime.Now.Year) +
string.Format("MM", DateTime.Now.Month) +
string.Format("dd", DateTime.Now.Day)

string.Format("HH", DateTime.Now.TimeOfDay.Hours) + string.Format("mm", DateTime.Now.TimeOfDay.Minutes)
0
Comment
Question by:CipherIS
[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
3 Comments
 
LVL 9

Expert Comment

by:dustock
ID: 38775051
instead of using yyyy,MM, etc replace with {0} to hold the value.

You could do this:
string.Format("Date {0} {1}, {2} Time {3}:{4}", DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Year, DateTime.Now.TimeOfDay.Hours, DateTime.Now.TimeOfDay.Minutes)
0
 
LVL 1

Accepted Solution

by:
CipherIS earned 0 total points
ID: 38775063
Figured it out

DateTime.Now.ToString("yyyyMMddHHmm")
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 38796076
Figured it out
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

650 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