Avatar of isnoend2001
isnoend2001
Flag for United States of America asked on

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
Visual Basic Classic

Avatar of undefined
Last Comment
isnoend2001

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Martin Liss

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
isnoend2001

ASKER
Thanks Marty
will that work for times also ?
Martin Liss

Yes.
isnoend2001

ASKER
Thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
isnoend2001

ASKER
how could this be valid : "11/15/896" is it my vb or ?
Martin Liss

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

isnoend2001

ASKER
thanks glad you added that
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Martin Liss

I just realized that IsDateEx probably won't work for times.
isnoend2001

ASKER
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
isnoend2001

ASKER
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
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
isnoend2001

ASKER
this is valid by vb "14:36am"
but this not
"10:61am"
it seems the minutes are correct, but not the hours
Martin Liss

Please start a new question.
isnoend2001

ASKER
ok in just a few minutes
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.