Syntax :
CDate ( expression )
expression : String or number that can be evaluated as a legal date or time
CDate ( expression )
expression : String or number that can be evaluated as a legal date or time
CDate input Handling
Input Value Return Value
Numeric, -657434 to 2958468 Date
Numeric, Out of range Error 13 ( Type Mismatch)
String that looks like a date Date
String that looks like a number Date , if number in range; Error 13 if out of range
Other String expression Error 13 ( Type Mismatch )
Option Explicit
Private Sub Form_Load()
Dim InDate As String, OutDate As Date, Msg, TABSTOP
TABSTOP = Chr$(9)
Do
Msg = "Enter any date and time in any format you like."
InDate = InputBox (Msg)
If InDate = "" Then Exit Sub
If Len(Format(InDate, "mm-dd-yy")) <> 8 Or Format(InDate, "mm-dd-yy") = "01-01-00" Or (Len(InDate) = 8 And Val(InDate) = 0) Then
MsgBox " invalid date ! Try again. ", 48
Else
OutDate = CDate(InDate)
Msg = "You entered : " & TABSTOP & InDate & vbCrLf
Msg = Msg & "Long Form : " & TABSTOP & Format(OutDate, "mmmm dd, yyyy") & vbCrLf
Msg = Msg & "Long Time : " & TABSTOP & Format(OutDate, "hh:MM:ss AM/PM") & vbCrLf
Msg = Msg & "Serial Time: " & TABSTOP & CStr(CDbl(OutDate))
MsgBox Msg
End If
Loop
End Sub
Private Sub Form_Load()
Dim InDate As String, OutDate As Date, Msg, TABSTOP
TABSTOP = Chr$(9)
Do
Msg = "Enter any date and time in any format you like."
InDate = InputBox (Msg)
If InDate = "" Then Exit Sub
If Len(Format(InDate, "mm-dd-yy")) <> 8 Or Format(InDate, "mm-dd-yy") = "01-01-00" Or (Len(InDate) = 8 And Val(InDate) = 0) Then
MsgBox " invalid date ! Try again. ", 48
Else
OutDate = CDate(InDate)
Msg = "You entered : " & TABSTOP & InDate & vbCrLf
Msg = Msg & "Long Form : " & TABSTOP & Format(OutDate, "mmmm dd, yyyy") & vbCrLf
Msg = Msg & "Long Time : " & TABSTOP & Format(OutDate, "hh:MM:ss AM/PM") & vbCrLf
Msg = Msg & "Serial Time: " & TABSTOP & CStr(CDbl(OutDate))
MsgBox Msg
End If
Loop
End Sub
No comments:
Post a Comment