DateTime.ToString problem

Posted on 2008-06-18
Last Modified: 2013-12-16
i'm reading in a datetime from a database and then outputting to another text file.
However, the following code appears to display a date incorrect...such as: 18 00 2008
myCurrentLine.Append(((DateTime)this.m_Headers.Rows[this.m_HeadersProcessed + i]["Order Date"]).ToString("dd mm yyyy"));

If i leave it without formatting:
myCurrentLine.Append(((DateTime)this.m_Headers.Rows[this.m_HeadersProcessed + i]["Order Date"]).ToString());
i get the following result: 18/06/2008 00:00:000

What i need to display is just: 18 06 2008

any ideas why its setting the month incorrectly with this code:
myCurrentLine.Append(((DateTime)this.m_Headers.Rows[this.m_HeadersProcessed + i]["Order Date"]).ToString("dd mm yyyy"));
Question by:zell71

Accepted Solution

Sh4d1 earned 350 total points
ID: 21812908
Use this:
myCurrentLine.Append(((DateTime)this.m_Headers.Rows[this.m_HeadersProcessed + i]["Order Date"]).ToString("dd MM yyyy"));

Open in new window


Assisted Solution

orcic earned 150 total points
ID: 21812941
Just a short explanation:
mm is used for minutes
MM is for used for month

Author Closing Comment

ID: 31468343
Due to the time would be harsh to just award points to the first answer as you both probably posted at the same time.
both correct! cheers guys

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

22 Experts available now in Live!

Get 1:1 Help Now