Go Back   Velocity Reviews > Newsgroups > DotNet
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

DotNet - 'String was not recognized as a valid DateTime

 
Thread Tools Search this Thread
Old 04-20-2005, 02:39 PM   #1
Default 'String was not recognized as a valid DateTime


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


Pial
  Reply With Quote
Old 04-21-2005, 05:32 AM   #2
singh_angrez@rediffmail.com
 
Posts: n/a
Default Re: 'String was not recognized as a valid DateTime
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



singh_angrez@rediffmail.com
  Reply With Quote
Old 04-21-2005, 05:34 AM   #3
sachintana
 
Posts: n/a
Default Re: 'String was not recognized as a valid DateTime
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" wrote in message
news: om...
>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





sachintana
  Reply With Quote
Old 04-21-2005, 02:42 PM   #4
Pial
 
Posts: n/a
Default Re: 'String was not recognized as a valid DateTime
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

"" <> wrote in message news:< oups.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



Pial
  Reply With Quote
Old 04-28-2005, 07:53 AM   #5
Maqsood Ahmed
 
Posts: n/a
Default Re: 'String was not recognized as a valid DateTime
Hello,
Please try to use CurrentCulture's DateTimeFormat property.

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

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

*** Sent via Developersdex http://www.developersdex.com ***


Maqsood Ahmed
  Reply With Quote
Old 04-28-2005, 07:55 AM   #6
Maqsood Ahmed
 
Posts: n/a
Default Re: 'String was not recognized as a valid DateTime
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 ***


Maqsood Ahmed
  Reply With Quote
Old 04-28-2005, 01:21 PM   #7
Nassos
 
Posts: n/a
Default Re: 'String was not recognized as a valid DateTime
Hi Pial,
Instead of DateTime.Parser use Convert.ToDateTime(string date).
Hope that works for you.
"Pial" <> wrote in message
news: om...
>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





Nassos
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Give you enough string functions in Java web reporting tool freezea Software 0 10-08-2009 09:03 AM
urgent help....need urgent help on say string task.. pooja Software 0 03-03-2009 06:16 AM
Java String Problems rbnbenjamin General Help Related Topics 0 02-03-2009 11:02 PM
ASP.NET: Asign Users in Roles(Array.IndexOf(Of String) method) msandlana Software 0 04-25-2008 06:37 AM
Hidden linebreaks in string? VB.NET Jiggy Software 0 04-23-2008 02:18 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46