![]() |
is date?
Hi! i want to check if dates that i use as input into a program are valid
dates ie they exist. Now i have a rudimenatry control using the isDate function in vba. however that does not do it if i write an invalid date usijng the correct date format eg 2007-04-33. is there any way to check to see if a date is ok or not? i would really appreciate help regarding this matter. thanks alot! |
is date?
Sub arne()
Dim s As String Dim d As Date s = Application.InputBox("enter date", 2) MsgBox (s) d = DateValue(s) MsgBox (d) End Sub gets the date as a pure string, can accept many formats. Accepts 2007-4-21 will raise an error on 2007-4-33. Just add on error code to handle it the way you want. -- Gary''s Student - gsnu200729 "Arne Hegefors" wrote: Hi! i want to check if dates that i use as input into a program are valid dates ie they exist. Now i have a rudimenatry control using the isDate function in vba. however that does not do it if i write an invalid date usijng the correct date format eg 2007-04-33. is there any way to check to see if a date is ok or not? i would really appreciate help regarding this matter. thanks alot! |
is date?
Arne,
In the immediate window: ?isdate("2007-04-33") False You mean this returns true for you ? NickHK "Arne Hegefors" wrote in message ... Hi! i want to check if dates that i use as input into a program are valid dates ie they exist. Now i have a rudimenatry control using the isDate function in vba. however that does not do it if i write an invalid date usijng the correct date format eg 2007-04-33. is there any way to check to see if a date is ok or not? i would really appreciate help regarding this matter. thanks alot! |
is date?
Hi Nick! Yes to me it seems like isDate only gives false when the actual
format is no good. when the date is nonsens but format is godd eg 2007-04-35 vba reads it like 00:00:00. si it fixed it lik this: If IsDate(datStartdate) = True Then If datStartdate = "00:00:00" Then MsgBox "Invalid start date. Please enter valid start date.", vbOKOnly, "Error message" Exit Sub End If End If "NickHK" skrev: Arne, In the immediate window: ?isdate("2007-04-33") False You mean this returns true for you ? NickHK "Arne Hegefors" wrote in message ... Hi! i want to check if dates that i use as input into a program are valid dates ie they exist. Now i have a rudimenatry control using the isDate function in vba. however that does not do it if i write an invalid date usijng the correct date format eg 2007-04-33. is there any way to check to see if a date is ok or not? i would really appreciate help regarding this matter. thanks alot! |
is date?
Maybe you can check the year to see if it's valid for your data:
Dim datStartDate As Date datStartDate = Application.InputBox(Prompt:="Enter a date", Type:=1) If Year(datStartDate) < 2005 _ Or Year(datStartDate) 2010 Then MsgBox "Please enter a valid date" Else MsgBox Format(datStartDate, "mmmm dd, yyyy") End If Application.inputbox with type:=1 won't let the user enter 2007-04-35. Arne Hegefors wrote: Hi Nick! Yes to me it seems like isDate only gives false when the actual format is no good. when the date is nonsens but format is godd eg 2007-04-35 vba reads it like 00:00:00. si it fixed it lik this: If IsDate(datStartdate) = True Then If datStartdate = "00:00:00" Then MsgBox "Invalid start date. Please enter valid start date.", vbOKOnly, "Error message" Exit Sub End If End If "NickHK" skrev: Arne, In the immediate window: ?isdate("2007-04-33") False You mean this returns true for you ? NickHK "Arne Hegefors" wrote in message ... Hi! i want to check if dates that i use as input into a program are valid dates ie they exist. Now i have a rudimenatry control using the isDate function in vba. however that does not do it if i write an invalid date usijng the correct date format eg 2007-04-33. is there any way to check to see if a date is ok or not? i would really appreciate help regarding this matter. thanks alot! -- Dave Peterson |
All times are GMT +1. The time now is 05:26 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com