Time difference and time range
im trying to work on a some code that will start then stop something if the current time is within a certain range. i have searched this forum and found code using datediff and timeserial, below, but it all works as long as both the start and stop time are either am or pm. my problem is when say the start time is 5:30 pm and the stop time is 6:00 am. the database time is just a access time/date field in format 5:30:00 PM
if have tried this, but the am pm is an issue
Code:
Dim date1 As Date
Dim date2 As Date
date1 = Format(rs2.Fields("BurnInOnTime").Value, "hh:mm:ss")
date2 = Format(rs2.Fields("BurnInOffTime").Value, "hh:mm:ss")
If DateDiff("n", date1, Time) >= 0 Then
If DateDiff("n", date2, Time) < 0 Then
Picture1.Visible = False ' blank out the picture box to display the all black full screen form
Exit Sub
End If
End If
Re: Time difference and time range
Quote:
Dim date1 As Date
Dim date2 As Date
date1 = Format(rs2.Fields("BurnInOnTime").Value, "hh:mm:ss")
date2 = Format(rs2.Fields("BurnInOffTime").Value, "hh:mm:ss")
as date1 and date2 are of type date the string returned from format would be converted back to a date, so pointless to format
Quote:
my problem is when say the start time is 5:30 pm and the stop time is 6:00 am.
and can start and finish time differences be greater than 12 or 24 hours?
which is the start and which is the stop time?
Re: Time difference and time range
Try Format(Time, "hh:mm:ss AMPM") so it's the same format as what it's being compared to. And I'd think that if you're dealing with 5pm one day and 6pm the next, you'd have to compare the full datetime, not just the time, in which case you'd have to add the current date onto the input.
Re: Time difference and time range
Quote:
Originally Posted by
westconn1
which is the start and which is the stop time?
From the first post:
Quote:
start time is 5:30 pm and the stop time is 6:00 am.