views:

145

answers:

2

I am trying to convert a string into date time format.

DateTime.Parse(tempfrmBankDetails.dgvBankDetails.SelectedRows[0].Cells["PaymentDate"].Value.ToString(),null);

This is printed as an output but i want it in dd/MM/yyyy format. How should i parse it {1/2/2010 12:00:00 AM} EDIT

I have created a custom control which accepts string input and their i am using mask as "00/00/2\000". Here i have done all the validation into my control so as to accept all valid date but they should be only in format dd/MM/yyyy. That's why i want to convert it into string

A: 

DateTime.ParseExact

Jonathan Allen
+3  A: 

Try this:

string stringValue = tempfrmBankDetails.dgvBankDetails.SelectedRows[0]
    .Cells["PaymentDate"].Value.ToString();
DateTime dateValue = DateTime.ParseExact(stringValue, "M/d/yyyy");

// use this when you need to show that formatted date value
string formattedDate = dateValue.ToString("dd/MM/yyyy");
Rubens Farias