Check valid dates and times for proper format vb6

I have a mshflexgrid that is editable by using a textbox and has 2 columns of dates/times
these dates/ times do calculations and need to be in the proper format
How can i determine if they are entered correctly ?
date time
isnoend2001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Dim MyDate As String

MyDate = "11/06/2015"

If IsDate(MyDate) Then
    MsgBox "Valid"
Else
    MsgBox "Not valid"
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isnoend2001Author Commented:
Thanks Marty
will that work for times also ?
0
Martin LissOlder than dirtCommented:
Yes.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

isnoend2001Author Commented:
Thanks
0
isnoend2001Author Commented:
how could this be valid : "11/15/896" is it my vb or ?
0
Martin LissOlder than dirtCommented:
That is surprising and while 896 is a year I would think that VB wouldn't consider it one since the usual minimum is 1900 (I think). In any case try this. The added IsDateEx function by default accepts only dates +/- 20 years from today's date. It could be changed to make it so the date has to be after today's date and the 20 years could be changed either by changing the default in the function or passing a smaller value as the second parameter to that function like IsDateEx(MyDate, 3) to ensure that a date can't be after 2018.

Private Sub YourSub()
Dim MyDate As String

MyDate = "11/15/896"

If IsDateEx(MyDate) Then
    MsgBox "Valid"
Else
    MsgBox "Not valid"
End If
End Sub

Private Function IsDateEx(strDate As String, Optional intSpan As Integer = 20) As Boolean

If IsDate(strDate) And Year(strDate) - intSpan <= Year(Now) And Year(strDate) + intSpan >= Year(Now) Then
    IsDateEx = True
Else
    IsDateEx = False
End If
End Function

Open in new window

0
isnoend2001Author Commented:
thanks glad you added that
0
Martin LissOlder than dirtCommented:
I just realized that IsDateEx probably won't work for times.
0
isnoend2001Author Commented:
I have not tested times for something out of the ordinary only, that it will be a time eg:
With gridMaster
if .textmatrix(.row, .col-1 = "Daily" then
it will have to a time
i will do some testing with times only thing i did so far was check if a space
was needed before the AMPM and it worked with a space and without
0
isnoend2001Author Commented:
found a problem this should not be a valid time, but vb says it is
"13:30am" vb says it's valid
i don't think any number over 12 should be valid for the hour in AM?PM format
0
isnoend2001Author Commented:
this is valid by vb "14:36am"
but this not
"10:61am"
it seems the minutes are correct, but not the hours
0
Martin LissOlder than dirtCommented:
Please start a new question.
0
isnoend2001Author Commented:
ok in just a few minutes
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.