<% '' Author Yasser Taeima www.TDCAD.com '' Version 4.5 '' This script contains two functions '' First one "inc_Date_ValidateDate" to validate a date value '' Second one "inc_Date_ValidateStartEndDate" to validate two dates entered and compare/check first occurs before the second '' Function to Validate a Date '' This function will return a string '' If the string is blank "" -- Valid date '' If the string is NOT blank -- date is invalid and the string will contain an error message. '' Parameters: '' FieldName -- '' The Field name of the date you are validating (It will be included in the Error Message if date is invalid) '' If passed a blank string "" It will generate generic error messages, if the date is invalid '' lngDay -- The Day value as integer '' lngMonth -- The Month value as integer '' lngYear -- The Year value as intger (four digit format) Private Function inc_Date_ValidateDate(FieldName , lngDay, lngMonth, lngYear) On Error Resume Next If StrComp(FieldName, "" , 1) <> 0 Then FieldName = " of " & FieldName End If If lngYear < 1 Then inc_Date_ValidateDate = "The Year" & FieldName & " is invalid" elseIf lngDay > 31 OR lngDay < 1 Then inc_Date_ValidateDate = "The Day" & FieldName & " should be between 1 and 31" elseif lngMonth > 12 OR lngMonth < 1 Then inc_Date_ValidateDate = "The Month" & FieldName & " should be between 1 and 12" elseif lngDay > 30 and _ ( lngMonth = 4 or lngMonth = 6 or lngMonth = 9 or lngMonth = 11) Then inc_Date_ValidateDate = "The Month" & FieldName & " doesn't have a 31st day" elseif lngDay > 29 and _ ( lngYear mod 4 ) = 0 and _ lngMonth = 2 then inc_Date_ValidateDate = "The Year" & FieldName & " only has 29 days in February" elseif lngDay > 28 and _ Not ( lngYear mod 4 ) = 0 and _ lngMonth = 2 then inc_Date_ValidateDate = "The Month (February)" & FieldName & " only has 28 days" Else inc_Date_ValidateDate = "" End If If Err.number <> 0 Then inc_Date_ValidateDate = "Internal Error During Validating the Date" Exit Function End If End Function '' Function to Validate a two Dates and compare/check first occurs before second '' This function will return a string '' If the string is blank "" -- Valid date '' If the string is NOT blank -- date is invalid and the string will contain an error message. '' Parameters: '' FieldName1 -- '' The Field name of the FIRST date you are validating (It will be included in the Error Message if date is invalid) '' If passed a blank string "" It will generate generic error messages, if the date is invalid '' FieldName2 -- '' The Field name of the Second date you are validating (It will be included in the Error Message if date is invalid) '' If passed a blank string "" It will generate generic error messages, if the date is invalid '' lngDayS -- The Start/First Date Day value as integer '' lngMonthS -- The Start/First Date Month value as integer '' lngYearS -- The Start/First Date Year value as intger (four digit format) '' lngDayE -- The End/Second Date Day value as integer '' lngMonthE -- The End/Second Date Month value as integer '' lngYearE -- The End/Second Date Year value as intger (four digit format) Private Function inc_Date_ValidateStartEndDate (FieldName1 , FieldName2 , lngDayS, lngMonthS, lngYearS, lngDayE, lngMonthE, lngYearE) On Error Resume Next Dim Temp Temp = inc_Date_ValidateDate(FieldName1 , lngDayS, lngMonthS, lngYearS) If StrComp(Temp,"",1) <> 0 Then inc_Date_ValidateStartEndDate = Temp Exit Function End If Temp = ValidateDate(FieldName2 , lngDayE, lngMonthE, lngYearE) If StrComp(Temp,"",1) <> 0 Then inc_Date_ValidateStartEndDate = Temp Exit Function End If If StrComp(FieldName1, "" , 1) <> 0 Then FieldName1 = " of " & FieldName1 End If If StrComp(FieldName2, "" , 1) <> 0 Then FieldName2 = " of " & FieldName2 End If If lngYearS > lngYearE then inc_Date_ValidateStartEndDate = "You cannot start in year " + _ Cstr(lngYearS) + _ " and end in year " + _ Cstr(lngYearE) + "!!" elseif lngYearS = lngYearE and _ lngMonthS > lngMonthE then inc_Date_ValidateStartEndDate = "You cannot start in " + _ Cstr(lngMonthS) + "/" + Cstr(lngYearS) + _ " and end in " + _ Cstr(lngMonthE) + "/" + Cstr(lngYearS) + "!!" elseif lngYearS = lngYearE and _ lngMonthS = lngMonthE and _ lngDayS > lngDayE then inc_Date_ValidateStartEndDate = "You cannot start in " + _ Cstr(lngDayS) + "/" + Cstr(lngMonthS) + "/" + Cstr(lngYearS) + _ " and end in " + _ Cstr(lngDayE) + "/" + Cstr(lngMonthE) + "/" + Cstr(lngYearS) + "!!" Else inc_Date_ValidateStartEndDate = "" End If If Err.number <> 0 Then inc_Date_ValidateStartEndDate = "Internal Error" Exit Function End If End Function %>