Error:String was not recognized as a valid DateTime.

483 views
Skip to first unread message

vanitha palanisamy

unread,
Apr 30, 2008, 4:24:15 AM4/30/08
to DotNetDe...@googlegroups.com
Hi,
When i store the date from text box  to database am getting "String was not recognized as a valid DateTime" error.

I used

Format(Convert.ToDateTime(TxtStatrDate.Text), "yyyy/MM/dd")
Format(CDate(TxtStatrDate.Text), "yyyy/MM/dd")
 DateTime.Parse(TxtStatrDate.Text).ToString("yyyy/MM/dd")

 methods to convert into "yyy/MM/dd" format.But still d prob remains.
Plz can anyone help


Thankz in advance.

Vani.

Cerebrus

unread,
Apr 30, 2008, 3:12:02 PM4/30/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Perhaps you should tell us the format in which you are entering the
date into the textbox. I prefer to use DateTime.ParseExact() with a
FormatProvider that uses the Invariant culture.

Also, shouldn't your text field be spelled "txtStartDate" (please
ignore my proclivity for Camel casing)

vanitha palanisamy

unread,
May 1, 2008, 7:57:11 AM5/1/08
to DotNetDe...@googlegroups.com
thakz for reply.
I'm using "dd/MM/yyyy" format to display in textbox.
I used datetime.parseextract but still d prob remains.Plz help

 

Cerebrus

unread,
May 1, 2008, 1:12:40 PM5/1/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Here ya go ! :
---
if (! string.IsNullOrEmpty(txtStartDate.Text))
{
DateTime dt = DateTime.ParseExact(txtStartDate.Text, "dd/MM/yyyy",
new DateTimeFormatInfo());
return dt.ToString("yyyy/MM/dd");
}

---

On May 1, 4:57 pm, "vanitha palanisamy" <vanith...@gmail.com> wrote:
> thakz for reply.
> I'm using "dd/MM/yyyy" format to display in textbox.
> I used datetime.parseextract but still d prob remains.Plz help
>
> On 5/1/08, Cerebrus <zorg...@sify.com> wrote:
>
>
>
>
>
> > Perhaps you should tell us the format in which you are entering the
> > date into the textbox. I prefer to use DateTime.ParseExact() with a
> > FormatProvider that uses the Invariant culture.
>
> > Also, shouldn't your text field be spelled "txtStartDate" (please
> > ignore my proclivity for Camel casing)
>
> > On Apr 30, 1:24 pm, "vanitha palanisamy" <vanith...@gmail.com> wrote:
> > > Hi,
> > > When i store the date from text box  to database am getting "String was
> > not
> > > recognized as a valid DateTime" error.
>
> > > I used
>
> > > Format(Convert.ToDateTime(TxtStatrDate.Text), "yyyy/MM/dd")
> > > Format(CDate(TxtStatrDate.Text), "yyyy/MM/dd")
> > >  DateTime.Parse(TxtStatrDate.Text).ToString("yyyy/MM/dd")
>
> > >  methods to convert into "yyy/MM/dd" format.But still d prob remains.
> > > Plz can anyone help
>
> > > Thankz in advance.
>
> > > Vani.- Hide quoted text -
>
> - Show quoted text -

vanitha palanisamy

unread,
May 2, 2008, 2:34:17 AM5/2/08
to DotNetDe...@googlegroups.com
thankz a lot.
now working without bug.Once again thankz

Cerebrus

unread,
May 2, 2008, 1:48:18 PM5/2/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Assuming that "thankz" is slang for "thanks", you're welcome ! ;-)
Reply all
Reply to author
Forward
0 new messages