|
 |
aspx thread: STRING TO DATETIME IN MONTH FORMAT ???
Message #1 by "Rohit Arora" <rohit_arora@i...> on Fri, 13 Dec 2002 12:53:54 +0530
|
|
hie group,
I am converting a string ivuDate into a datetime for comparing it with a
date which is in month-date-year format and even my string is but while
comparison it gives error which u can see below ??? pl help me out of this
----------------------------------
?ivuDate.Text
"26/11/2002"
?System.Convert.ToDateTime("26/11/2002")
{System.FormatException}
System.SystemException: {"String was not recognized as a valid
DateTime."}
----------------------------------
Thanx in advance,
Regards,
Rohit
Message #2 by "Juan T. Llibre" <j.llibre@c...> on Fri, 13 Dec 2002 10:37:56 -0400
|
|
Have you tried 11/26/2002 ?
(month-day-year)
Juan T. Llibre
Microsoft MVP [IIS/ASP]
Foros de ASP.NET en Espaņol : http://asp.net.do/Foros/
=========================================
----- Original Message -----
From: "Rohit Arora" <rohit_arora@i...>
To: "ASP.NET" <aspx@p...>
Sent: Friday, December 13, 2002 3:23 AM
Subject: [aspx] STRING TO DATETIME IN MONTH FORMAT ???
> hie group,
> I am converting a string ivuDate into a datetime for comparing it with a
> date which is in month-date-year format and even my string is but while
> comparison it gives error which u can see below ??? pl help me out of this
>
>
> ----------------------------------
> ?ivuDate.Text
> "26/11/2002"
> ?System.Convert.ToDateTime("26/11/2002")
> {System.FormatException}
> System.SystemException: {"String was not recognized as a valid
> DateTime."}
> ----------------------------------
>
> Thanx in advance,
>
> Regards,
> Rohit
>
>
Message #3 by "Arjen Oetomo" <arjeno@c...> on Mon, 16 Dec 2002 07:36:22
|
|
You need first to convert the date in the correct format. For example for
dutch format (DD/MM/YYYY):
If ValidateDate(inputDate) = true Then
myDate = DateTime.Parse(inputDate, New
System.Globalization.CultureInfo("nl-NL"))
Else
' No correct format...
End If
Before converting it you need some inputvalidation. Here is a sample of a
regular expression that validates the supplied date in the format
DD/MM/YYYY.
' valides dates in the DD/MM/YYYY-format
Public Function ValidateDate(ByVal inputString As String) As Boolean
Dim regEvalString As String = "^(?:(?:31(\/|-|\.)(?:0?[13578]|1
[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]
\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468]
[048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1
\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})
$"
Dim regExpVal As System.Text.RegularExpressions.Regex
regExpVal = New System.Text.RegularExpressions.Regex(regEvalString)
return regExpVal.Match(inputString).Success
End Function
> hie group,
I am converting a string ivuDate into a datetime for comparing it with a
date which is in month-date-year format and even my string is but while
comparison it gives error which u can see below ??? pl help me out of this
----------------------------------
?ivuDate.Text
"26/11/2002"
?System.Convert.ToDateTime("26/11/2002")
{System.FormatException}
System.SystemException: {"String was not recognized as a valid
DateTime."}
----------------------------------
Thanx in advance,
Regards,
Rohit
|
|
 |