.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> DateTime >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Some Date Validation in VB.NET

Posted By:Athira Sreejith       Posted Date: March 24, 2009    Points: 10    Category: DateTime    URL: http://www.dotnetspark.com  
 

This vb.net code example to validate datetime in asp.net

Public Class Utils
    Public Function FormatDate(ByVal strDate As String) As String
        Dim strRetDate As Date = CDate(strDate)
        Return Right(CStr(100 + Day(strRetDate)), 2) + "-" + Right(CStr(100 + Month(strRetDate)), 2) + "-" + CStr(Year(strRetDate))
    End Function

    Public Function getOracleDate(ByVal strDate As String) As String
        strDate = Replace(strDate, "-", "/")
        Dim strRetDate As String
        strRetDate = Mid(strDate, 1, 2) + "-" + getMonth(Mid(strDate, 4, 2)) + "-" + Mid(strDate, 7, 4)
        If strRetDate = "--" Or strRetDate = "N/--" Then
            strRetDate = ""
        End If
        Return strRetDate
    End Function
    Public Function getMonth(ByVal strMM As String) As String
        If strMM = "01" Then
            strMM = "Jan"
        End If
        If strMM = "02" Then
            strMM = "Feb"
        End If
        If strMM = "03" Then
            strMM = "Mar"
        End If
        If strMM = "04" Then
            strMM = "Apr"
        End If
        If strMM = "05" Then
            strMM = "May"
        End If
        If strMM = "06" Then
            strMM = "Jun"
        End If
        If strMM = "07" Then
            strMM = "Jul"
        End If
        If strMM = "08" Then
            strMM = "Aug"
        End If
        If strMM = "09" Then
            strMM = "Sep"
        End If
        If strMM = "10" Then
            strMM = "Oct"
        End If
        If strMM = "11" Then
            strMM = "Nov"
        End If
        If strMM = "12" Then
            strMM = "Dec"
        End If
        Return strMM
    End Function


    Public Function checkFrToDate(ByVal fDate As Date, ByVal tDate As Date) As Boolean
        Dim rFlag As Boolean = False
        If fDate <= tDate Then
            rFlag = True
        End If
        Return rFlag
    End Function

    Public Function CurrDateValidate(ByVal fDate As Date) As Boolean
        Dim rFlag As Boolean = False
        If fDate <= Now Then
            rFlag = True
        End If
        Return rFlag
    End Function
    Public Function DateValidate(ByVal fDate As String) As Boolean
        Dim rFlag As Boolean = False
        Dim chkDate As Date
        Try
            chkDate = CDate(fDate)
            rFlag = True
        Catch ex As Exception
            rFlag = False
        End Try
        Return rFlag
    End Function


End Class


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend