Hi
How i pass String to time object
example
Dim MyTime As Date
MyTime=“7:20 PM”
Hi
How i pass String to time object
example
Dim MyTime As Date
MyTime=“7:20 PM”
You could use the sqlDateTime property of date:
dim d as new date
d.sqlDateTime="2015-07-31 19:36:32"
thanks
but i need to compare two times
[quote]dim mytime as new date
mytime.totalseconds = 0
mytime.hour = 19
mytime.minute = 20[/quote]
hi Simon
but how i convert from 12 Hour to 24 Hour
By adding 12 hours if it’s PM
This function takes a string, and converts it to 24 hour time format
returns TRUE/FALSE depending on if it succeeed or failed
accepts
7pm 7p 7:00 19:00 etc…
assumes AM if not specified or not 24 hr format input
FUNCTION isValidTime(byref in_time As String) as boolean
Dim i As Integer
Dim s As String
Dim v() As String
Dim am_pm As Boolean
s=Trim(in_time)
s=cleanup_slashes(s,False)
If IsNumeric(s) Then
If Val(s)>=100 And Val(s)<=2359 Then
s=Left(s,Len(s)-2)+":"+Right(s,2)
End If
End If
If Right(s,2)="am" Then
s=Left(s,Len(s)-2)
Elseif Right(s,2)="pm" Then
s=Left(s,Len(s)-2)
am_pm=True
Elseif Right(s,1)="a" Then
s=Left(s,Len(s)-1)
Elseif Right(s,1)="p" Then
s=Left(s,Len(s)-1)
am_pm=True
End If
s=Trim(s)
If s="" Then Return False
v=Split(s,":")
If v.ubound=0 Then v.Append "0" 'at least have minutes.
If v.Ubound>2 Then Return False ' too many pieces to "time" 00:00:00
For i=0 To v.Ubound
If Not IsNumeric(v(i)) Then Return False
If Val(v(i))<0 Or Val(v(i))>59 Then Return False
Next i
' now have 2 or 3 numeric pieces
i=Val(v(0))
If i<=12 And am_pm Then i=i+12
If i>24 Then Return False
If Val(v(1))>59 Then Return False
in_time=Format(i,"00")+:=":"Format(Val(v(1)),"00") // time is in 24hour format
Return True
FUNCTION cleanup_slashes(t As String,include_colon as boolean=true) as string
Dim s As String=" -.\\:,;+"
Dim i As Integer
For i=1 To Len(s)
If (Mid(s,i,1)=":" Or Mid(s,i,1)=" ") And Not include_colon Then Continue
t=ReplaceAll(t,Mid(s,i,1),"/")
Next i
While InStr(t,"//")>0
t=ReplaceAll(t,"//","/")
Wend
While Right(t,1)="/"
t=Left(t,Len(t)-1)
If t="" Then Exit While
Wend
If Right(t,2)="/a" Or Right(t,2)="/p" Then t=t+"m"
If Right(t,3)="/am" Or Right(t,3)="/pm" Then t=Left(t,Len(t)-3)+Right(t,2)
Return t
[quote=203845:@Alexis Colon Lugo]Hi
How i pass String to time object
example
Dim MyTime As Date
MyTime=“7:20 PM”[/quote]
There’s no “time” data type - so the closest you will get for this is a date which is both a date and time.
To compare times pick some arbitrary day and then just set the values for whatever time you have
By using the same date the comparison will effectively ignore the date and only compare the times
ok
thanks to all