Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Convert.ToDateTime(txtdob.Text,"dd/mm/yyyy")
i get an exception of this
 
String was not recognized as a valid DateTime.
 
plz help me
Posted 22-Apr-13 1:02am
h1emu:)430
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

To convert DateTime format check your System datetime format. It will convert to your system datetime format
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

try this...
txtbox.Text = "12/30/1990"
string var=Convert.ToDateTime(txtbox.Text).ToString("dd/MM/yyyy");
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
you can make use of DateTime.TryParse function.
 
refer DateTime.TryParse Method [^]
 
hope it helps.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

var date=DateTime.MinValue;
var dateStr=string.Empty;
if(DateTime.TryParse(txtMyDate.Text, out date))
{
  dateStr=date.ToString("dd/MM/yyyy");
}
 
But as ratnakargudipati said, it is dependent on System Date time Format.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

If your textbox takes date in dd/MM/yyyy format, the following code will convert it into valid datetime value:
string InputDate = YourDateTextBoxId.Text.Trim();
System.Globalization.DateTimeFormatInfo dateInfo = new System.Globalization.DateTimeFormatInfo();
dateInfo.ShortDatePattern = "dd/MM/yyyy";
DateTime OutputDate = Convert.ToDateTime(InputDate, dateInfo); 
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Try this:-
 
DateTime date = DateTime.ParseExact(txtdob.Text, "dd/MM/yyyy", null);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

try these,
 
txtbox.Text = "2/30/1990";
dateTime dt=txtbox.toShortDateString();
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,656
1 Sergey Alexandrovich Kryukov 6,490
2 CPallini 5,310
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100