Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

asked on

i have an editable mshflexgrid that a user can enter dates/times the app does calculations on these entries and need to make sure they are entered in the correct format

this fixes the date problem

this fixes the date problem

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

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
but now have aproblem with the time
this is valid by vb "14:36am"
but this not
"10:61am"
it seems the minutes are correct, but not the hours

how can yhis be corrected?
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

date_time_format.jpg
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

this is valid by vb "14:36am"
but this not
"10:61am"
10:61 is not a valid time, so vb is correct.

Why are you having people enter dates rather then picking them from a date picker control?
Avatar of isnoend2001

ASKER

The dates time are entered by datepicker, this gives the correct format, but i am trying to give the user the ability to change if neccessary. eg;
sisters doctor called and changed her app time from 1:30 to 3:30
tried to edit the question an put the proper code tags, but was denied
I'm confused. If this is about appointment times, and the dates are entered by way of the datepicker, why did you ask about "11/15/896"?

Also you can change the datepicker to act as a timepicker by setting one of it's properties, so validating either the date or the time should not be an issue.
vb says this is valid
"14:36am"
should this be PM to be valid ?
14:36 should not show either am or pm. It's 24-hour (military) time and it is understood that that's an afternoon time.
after more thought in the am/pm format
the bours can never be  more than 12
I want to force the user to enter am/pm time
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks
I guess, if the grid expects a time instead of allowing edit i could open date picker