Members
Technology Zones
Articles
Hosted By
Info
|
Rated
Read 33,477 times
Related Categories
Date And Time Validation Functions - Date and Time Validate Funtion
Date and Time Validate Funtion
Public Enum
OptFormat DDMMYYYY = 1 DDMMMYYYY = 2 End Enum
Public Function gfncIsDateValid( ByVal strDate As String , ByVal strValidFormat As OptFormat, Optional ByVal strDateOptional As Boolean = True ) As Boolean if Date can be empty. Dim strGetDate As String Dim strGetDay As String , strGetMonth As String , strGetYear As String Dim strDaysInMonth As String strGetDate = Trim(strDate) If strGetDate ="" Then If strDateOptional = True Then Return True Else Return False End If End If Select Case strValidFormat Case OptFormat.DDMMYYYY If Not Len(Trim(strGetDate)) = 10 Then Return False End If If InStr(strGetDate, pstrDateDelimiter, CompareMethod.Binary) = 0 Then Return False End If If ((strGetDate.Substring(2, 1) <> pstrDateDelimiter) Or (strGetDate.Substring(5, 1) <> pstrDateDelimiter)) Then Return False End If strGetDay = strGetDate.Substring(0, 2)strGetMonth = strGetDate.Substring(3, 2)strGetYear = strGetDate.Substring(6, 4) If Not ((IsNumeric(strGetDay)) And (IsNumeric(strGetMonth)) And (IsNumeric(strGetYear))) Then Return False End If If ((strGetDay < "0") Or (strGetMonth < "0") Or (strGetYear < "0")) Then Return False End If If ((strGetMonth = "01") Or (strGetMonth = "03") Or (strGetMonth = "05") Or (strGetMonth = "07") Or (strGetMonth = "08") Or (strGetMonth = "10") Or (strGetMonth = "12")) Then strDaysInMonth = "31" ElseIf ((strGetMonth = "04") Or (strGetMonth = "06") Or (strGetMonth = "09") Or (strGetMonth = "11")) Then strDaysInMonth = "30" ElseIf (strGetMonth = "02") Then If ( CInt (strGetYear) Mod 4) = 0 Then strDaysInMonth = "29" Else strDaysInMonth = "28" End If Else Return False End If If (strGetDay > strDaysInMonth) Then Return False Else Return True End If Case OptFormat.DDMMMYYYY If Not Len(Trim(strGetDate)) = 11 Then Return False End If If InStr(strGetDate, pstrDateDelimiter, CompareMethod.Binary) = 0 Then Return False End If If ((strGetDate.Substring(2, 1) <> pstrDateDelimiter) Or (strGetDate.Substring(6, 1) <> pstrDateDelimiter)) Then Return False End If strGetDay = strGetDate.Substring(0, 2)strGetMonth = strGetDate.Substring(3, 3).ToUpper()strGetYear = strGetDate.Substring(7, 4) If Not ((IsNumeric(strGetDay)) And (IsNumeric(strGetYear))) Then Return False End If If ((strGetDay < "0") Or (strGetYear < "0")) Then Return False End If If ((strGetMonth = "JAN") Or (strGetMonth = "MAR") Or (strGetMonth = "MAY") Or (strGetMonth = "JUL") Or (strGetMonth = "AUG") Or (strGetMonth = "OCT") Or (strGetMonth = "DEC")) Then strDaysInMonth = "31" ElseIf ((strGetMonth = "APR") Or (strGetMonth = "JUN") Or (strGetMonth = "SEP") Or (strGetMonth = "NOV")) Then strDaysInMonth = "30" ElseIf (strGetMonth = "FEB") Then If ( CInt (strGetYear) Mod 4) = 0 Then strDaysInMonth = "29" Else strDaysInMonth = "28" End If Else Return False End If If (strGetDay > strDaysInMonth) Then Return False Else Return True End If End Select End Function Public Function gfncFormatedDate( ByVal strDate As String , ByVal strValidFormat As OptFormat, Optional ByVal strDateOptional As Boolean = True ) As String Format Type DDMMYYYY and Type DDMMMYYYY are be Dim strGetDate As String Dim strGetDay As String , strGetMonth As String , strGetYear As String Dim strDaysInMonth As String strGetDate = Trim(strDate) Select Case strValidFormat Case OptFormat.DDMMYYYYstrGetDay = strGetDate.Substring(0, 2)strGetMonth = strGetDate.Substring(3, 2)strGetYear = strGetDate.Substring(6, 4) Return strGetDay & "/" & gfncGetMonth(strGetMonth) & "/" & strGetYear Case OptFormat.DDMMMYYYYstrGetDay = strGetDate.Substring(0, 2)strGetMonth = strGetDate.Substring(3, 3).ToUpper()strGetYear = strGetDate.Substring(7, 4) Return strGetDay & "/" & strGetMonth & "/" & strGetYear End Select End Function Private Function gfncGetMonth( ByVal strMonth As String ) As String Select Case strMonth Case"01" Return"Jan" Case"02" Return"Feb" Case"03" Return"Mar" Case"04" Return"Apr" Case"05" Return"May" Case"06" Return"Jun" Case"07" Return"Jul" Case"08" Return"Aug" Case"09" Return"Sep" Case"10" Return"Oct" Case"11" Return"Nov" Case"12" Return"Dev" End Select End Function Public Function gfncIsTimeValid( ByVal strTime As String , Optional ByVal strTimeOptional As Boolean = True ) As Boolean and True or False should be passed as 2nd param. if time can be empty. empty. in Valid Dim strHour As String Dim strMinute As String strTime = Replace(Trim(strTime), " ", "") If strTime ="" Then If strTimeOptional = True Then Return True Else Return False End If End If If (Len(strTime) <> 5) Then Return False End If If (strTime.Substring(2, 1) <> pstrTimeDelimiter) Then Return False End If strHour = strTime.Substring(0, 2)strMinute = strTime.Substring(3, 2) If Not ((IsNumeric(strHour)) And (IsNumeric(strMinute))) Then Return False End If If ((strHour < "0") Or (strMinute < "0")) Then Return False End If If ((strHour < "0") Or (strHour < "23")) Then Return False End If If ((strMinute < "0") Or (strMinute > "59")) Then Return False End If Return True End Function
I am Hari, SSE in a Pvt Firm. I have knowledge in Dot Net, VB6, Visual Foxpro, Foxpro, SQL Server, Oracle, Access, DBase and Crystal Report.
Comments
|
Search
Code Samples
New Members
|