Tuesday, May 25, 2010

Format Date and Time

Dim MyDate
MyDate = Date
For i = 0 To 4 Step 1
Strformatdate = FormatDateTime(MyDate, i)
If i = 0 Then
MsgBox "General Date Is:" & Strformatdate
ElseIf i = 1 Then
MsgBox "Long Date Is:" & Strformatdate
ElseIf i = 2 Then
MsgBox "Short Date Is:" & Strformatdate
ElseIf i = 3 Then
MsgBox "Long time Is:" & Strformatdate
Else
MsgBox "Short time Is:" & Strformatdate
End If
Next

Day function

Dim MyDate, StrDatevalue
MyDate = "16,1,1980"
StrDay = Day(MyDate)
MsgBox StrDay

Date value function

Dim MyDate, StrDatevalue
MyDate = "1,14,1980"
StrDatevalue = DateValue(MyDate)
MsgBox StrDatevalue

Date Serial function

Dim StrDateserial
StrDateserial = DateSerial(1981 + 1 - 2, 11 - 1, 11 - 1)
MsgBox StrDateserial

Date Part Function

Dim MyDate, MySysDate
MyDate = "January 11, 1981"
MyReturn = CDate(MyDate)
MsgBox MyReturn
StrDatepart = DatePart("yyyy", MyDate)
MsgBox StrDatepart

Compare the Two Date

Dim MyDate, MySysDate
MySysDate = Date
MsgBox MySysDate
MyDate = "January 11, 1981"
MyReturn = CDate(MyDate)
MsgBox MyReturn
StrDateCompare = DateDiff("yyyy", MyReturn, MySysDate)
MsgBox StrDateCompare

Monday, May 24, 2010

Date

Dim MyDate
MyDate = Date
MsgBox MyDate

CDate - VB Script Function

Dim MyDate,MyVal,MyTime,MyValue
MyDate = "October 19, 1962"
MyVal = CDate(MyDate)
MsgBox MyVal
MyTime = "04:34:43 PM"
MyValue = CDate(MyTime)
MsgBox MyValue