DateFormat
-
Hi All, In .net,I have to convert a string into date in a format 'dd/MM/yyyy'. My Code is System::DateTime ^dt=Convert::ToDateTime(this->txtModifiedDt->Text); try { String ^str=String::Format("{0,9:dd/MM/yyyy}",dt); MessageBox::Show(str); } catch(Exception ^e1) { MessageBox::Show(e1->Message); } its working fine when I type in the order of dd/mm/yyyy format But when i type for example: 08/13/2006.it is giving error that exception has occurred. But what i need ,it should automatically convert date as 13,month as 08 . ie like 13/08/2006 Is there any way to do like that Thanks in advance Nagaraju
-
Hi All, In .net,I have to convert a string into date in a format 'dd/MM/yyyy'. My Code is System::DateTime ^dt=Convert::ToDateTime(this->txtModifiedDt->Text); try { String ^str=String::Format("{0,9:dd/MM/yyyy}",dt); MessageBox::Show(str); } catch(Exception ^e1) { MessageBox::Show(e1->Message); } its working fine when I type in the order of dd/mm/yyyy format But when i type for example: 08/13/2006.it is giving error that exception has occurred. But what i need ,it should automatically convert date as 13,month as 08 . ie like 13/08/2006 Is there any way to do like that Thanks in advance Nagaraju
Hello Nagaraju I think there is no way to automatically do this. You could check the input manually, but you will have to choose a standard way of interpreting, because if the user enters 09/08/2006 it could be interpreted both ways. Kind Regards, John Petersen
-
Hi All, In .net,I have to convert a string into date in a format 'dd/MM/yyyy'. My Code is System::DateTime ^dt=Convert::ToDateTime(this->txtModifiedDt->Text); try { String ^str=String::Format("{0,9:dd/MM/yyyy}",dt); MessageBox::Show(str); } catch(Exception ^e1) { MessageBox::Show(e1->Message); } its working fine when I type in the order of dd/mm/yyyy format But when i type for example: 08/13/2006.it is giving error that exception has occurred. But what i need ,it should automatically convert date as 13,month as 08 . ie like 13/08/2006 Is there any way to do like that Thanks in advance Nagaraju
Use
DateTime::Parse
orDateTime::TryParse
in .NET 2.0 to get more control thanConvert::ToDateTime
offers.Stability. What an interesting concept. -- Chris Maunder
-
Hi All, In .net,I have to convert a string into date in a format 'dd/MM/yyyy'. My Code is System::DateTime ^dt=Convert::ToDateTime(this->txtModifiedDt->Text); try { String ^str=String::Format("{0,9:dd/MM/yyyy}",dt); MessageBox::Show(str); } catch(Exception ^e1) { MessageBox::Show(e1->Message); } its working fine when I type in the order of dd/mm/yyyy format But when i type for example: 08/13/2006.it is giving error that exception has occurred. But what i need ,it should automatically convert date as 13,month as 08 . ie like 13/08/2006 Is there any way to do like that Thanks in advance Nagaraju