Paul
Paul

Reputation: 197

Changing the format that Convert.ToDateTime is produced in

I have "02 September 2011" as string and I want to convert it to "02092011".

I am using Convert.ToDateTime("02 September 2011") and I am getting "dd/mm/yyyy 00:00:00".

How to format so not to include the time?

Upvotes: 0

Views: 6554

Answers (3)

Senthil
Senthil

Reputation: 106

Convert.ToDateTime("02 September 2011").ToShortDateString()

Upvotes: 1

Cubicle.Jockey
Cubicle.Jockey

Reputation: 3328

The most simply scenario is a below:

Console.WriteLine(Convert.ToDateTime("02 September 2011").ToString("d"));
//Example output: 9/2/2011

Upvotes: 0

Tchami
Tchami

Reputation: 4787

Convert.ToDateTime("02 September 2011").ToString("ddMMyyyy")

See more DateTime formatting options here on MSDN

Upvotes: 8

Related Questions