Pages

Monday, 2 July 2012

Important and useful Date and Time functions

DateAdd : DateAdd function in VB.NET is used to return specified Date added into current Date to know that specified Date. In example given below we specified the Date after 10 day in current Date.


Public Sub Date_Add()

        MsgBox("Date after 10 days::" & DateAdd(DateInterval.Day, 10, Now.Date))

End Sub



DateDiff : DateDiff function in VB.NET is used to return the time interval between two Dates specified in the function. The time interval between two Date can be year, month, day, hour, minute and also can be a second. In example given below we only show date difference between day.

        Dim d1 As Date = #1/1/2012#
        Dim d2 As Date = #7/1/2012#
        Dim res As Long
        res = DateDiff(DateInterval.Day, d1, d2)
        MsgBox("Time difference between the dates is::" & res)

End Sub



IsDate : IsDate function in VB.NET is used to return a Boolean either True or False to specified that the expression is a valid format Date or not? In example given below we check a string value is a correct format Date and its return True.

Public Sub Is_Date()

        Dim curdate As String
        curdate = "5/31/2010"
        MsgBox("valid date::" & IsDate(curdate))

End Sub

No comments:

Post a Comment