Home All Groups Group Topic Archive Search About

'String was not recognized as a valid DateTime

Author
20 Apr 2005 1:39 PM
Pial
I am facing problem in the following situation:


I have a text box in the aspx file name: openDate. And my date format is mm/dd/yyyy.

C#:

private DateTime _opendate;

_openDate = DateTime.Parse(Request.Form["openDate"]);

I get error saying 'String was not recognized as a valid DateTime'

thanks in advance

Zahir

Author
21 Apr 2005 4:32 AM
singh_angrez@rediffmail.com
Hi,

Just check what is the value you are getting from
Request.Form["openDate"].
I just works like this.

string date = "04/21/2005";   // in the format mm/dd/yyyy;
DateTime temp = DateTime.Parse(date);

//The above code runs without any exception.

Just check what the string are you getting using
Request.Form["open_date"];

Regards,
angrez
Fix windows and pc errors, click for free system scan

Author
21 Apr 2005 1:42 PM
Pial
Hi Angrez:

I check it with your code but the same error message, but one thing
when i change the format "21/04/2005" means(dd/mm/yyyy) it is working.
Is that means my machine system date is setting is dd/mm/yyyy....?
then how do i know that which format of date could use by the client!

Thanks in advance
Zahir

Show quoteHide quote
"singh_ang***@rediffmail.com" <singh_ang***@rediffmail.com> wrote in message news:<1114057950.922691.94280@z14g2000cwz.googlegroups.com>...
> Hi,
>
> Just check what is the value you are getting from
> Request.Form["openDate"].
> I just works like this.
>
> string date = "04/21/2005";   // in the format mm/dd/yyyy;
> DateTime temp = DateTime.Parse(date);
>
> //The above code runs without any exception.
>
> Just check what the string are you getting using
> Request.Form["open_date"];
>
> Regards,
> angrez
Author
28 Apr 2005 6:53 AM
Maqsood Ahmed
Hello,
Please try to use CurrentCulture's DateTimeFormat property.

DateTime dt = DateTime.Parse(dtString,
System.Threading.Tread.CurrentThread.CurrentCulture.DateTimeFormat);

HTH.
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Author
28 Apr 2005 6:55 AM
Maqsood Ahmed
but obviously, it'll work only if dtstring is in correct format
according to Current DateTime format of your computer (or current
thread) :)

Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Author
21 Apr 2005 4:34 AM
sachintana
Error occured when openDate query string is not in the date format
(mm/dd/yyyy).

Please use try, catch between your code lines.
And check whether the _opendate variable is null before using it.

private DateTime _opendate;


try
{
    _opendate = DateTime.Parse(Request.Form["openDate"]);
}
    catch(FormatException ex)
{
    _opendate = null;
}

if(_opendate!=null)
{
    //Do what ever you want
}



Best regards,
sachintana-MCSD.NET


"Pial" zis***@gmail.com wrote in message
Show quoteHide quote
news:795114e5.0504200539.32a72af1@posting.google.com...
>I am facing problem in the following situation:
>
>
> I have a text box in the aspx file name: openDate. And my date format is
> mm/dd/yyyy.
>
> C#:
>
> private DateTime _opendate;
>
> _openDate = DateTime.Parse(Request.Form["openDate"]);
>
> I get error saying 'String was not recognized as a valid DateTime'
>
> thanks in advance
>
> Zahir
Author
28 Apr 2005 12:21 PM
Nassos
Hi Pial,
Instead of DateTime.Parser use Convert.ToDateTime(string date).
Hope that works for you.
Show quoteHide quote
"Pial" <zis***@gmail.com> wrote in message
news:795114e5.0504200539.32a72af1@posting.google.com...
>I am facing problem in the following situation:
>
>
> I have a text box in the aspx file name: openDate. And my date format is
> mm/dd/yyyy.
>
> C#:
>
> private DateTime _opendate;
>
> _openDate = DateTime.Parse(Request.Form["openDate"]);
>
> I get error saying 'String was not recognized as a valid DateTime'
>
> thanks in advance
>
> Zahir

Bookmark and Share