Dim dt as Date
堅(jiān)守“ 做人真誠 · 做事靠譜 · 口碑至上 · 高效敬業(yè) ”的價(jià)值觀,專業(yè)網(wǎng)站建設(shè)服務(wù)10余年為成都成都發(fā)電機(jī)維修小微創(chuàng)業(yè)公司專業(yè)提供成都定制網(wǎng)頁設(shè)計(jì)營(yíng)銷網(wǎng)站建設(shè)商城網(wǎng)站建設(shè)手機(jī)網(wǎng)站建設(shè)小程序網(wǎng)站建設(shè)網(wǎng)站改版,從內(nèi)容策劃、視覺設(shè)計(jì)、底層架構(gòu)、網(wǎng)頁布局、功能開發(fā)迭代于一體的高端網(wǎng)站建設(shè)服務(wù)。
Dim s="2009-12-32"
if NOT Date.TryPhrase(s,dt) then
'日期無效代碼
end if
Private Sub Command1_Click()
Dim myYear, myMonth, myDay, myWeek, Days As Integer
Dim myDate As StringmyYear = Val(TextY.Text)
myMonth = Val(TextM.Text)
myDay = Val(TextD.Text)
If myYear 1980 Or myYear 9999 Then
MsgBox "輸入的年份應(yīng)在[1980, 9999]之間"
Exit Sub
End If
If myMonth 1 Or myMonth 12 Then
MsgBox "輸入的月份應(yīng)在[1, 12]之間"
Exit Sub
End If
Select Case myMonth
Case 1, 3, 5, 7, 8, 10, 12
Days = 31
Case 4, 6, 9, 11
Days = 30
Case 2
If (myYear Mod 4 = 0) And (myYear Mod 100 0) Or (myYear Mod 400 = 0) Then
Days = 29
Else
Days = 28
End If
End SelectIf myDay 1 Or myDay Days Then
MsgBox "輸入的日期應(yīng)在[1, " + Format(Days) + "]之間"
Exit Sub
End IfmyDate = Format(myYear) + "/"
If myMonth 10 Then
myDate = myDate + "0"
End If
myDate = myDate + Format(myMonth) + "/"
If myDay 10 Then
myDate = myDate + "0"
End If
myDate = myDate + Format(myDay)
End Sub
If?IsDate(Text1.Text)?Then
MsgBox?"正確的日期格式"
Else
MsgBox?"錯(cuò)誤的日期格式"
End?If
要再高級(jí)點(diǎn)就是:
If?IsDate(Text1.Text)?Then
If?Format(Text1.Text,?"yyyy-m-d")?=?Text1.Text?Then
MsgBox?"正確的日期格式"
Else
MsgBox?"不是指定的日期格式(yyyy-m-d)"
End?If
Else
MsgBox?"錯(cuò)誤的日期格式"
End?If