I need help with my scheduling and I need a block of code to compare time .

Dani AI

Generated

pointed you toward Time$, which is the current system time returned as a string. That works for display, but string comparisons are fragile: formats (12/24h, separators, locale) change how strings sort. For scheduling you want to compare Date/Time values, not raw strings.

Validate the ComboBox text with IsDate, convert it into a Date that uses the same date as now, then compare or compute intervals with DateDiff. A simple, practical pattern:

' validate input first
If Not IsDate(Combo1.Text) Then
    MsgBox "Please pick a valid time."
    Exit Sub
End If

' combine today's date and the selected time
Dim selDT As Date
selDT = CDate(CStr(Date) & " " & Combo1.Text)

' if the time already passed today, assume next day
If selDT <= Now Then selDT = DateAdd("d", 1, selDT)

' minutes until the scheduled time
Dim minutesUntil As Long
minutesUntil = DateDiff("n", Now, selDT)

Notes and cautions: CDate and IsDate follow system locale, so accept AM/PM or 24h as your users expect. Use Time$ only for display; use Now, CDate, DateAdd, and DateDiff for reliable comparisons. See the docs for CDate, IsDate, and DateDiff for details: , IsDate function, DateDiff function.

Recommended Answers

All 3 Replies

you can compare times directly. For example

if Time$ < Text1.text

thnx for the reply,what this Time$ do and how does it work? can i use it with a combo box?, i really have no idea.

Time$ I think you need to start studying VB from the beginning. Either buy a good book or study some of the tutorials you can find with google.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.