|
-
Dec 22nd, 2012, 11:40 AM
#1
Thread Starter
Hyperactive Member
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
-
Dec 22nd, 2012, 09:01 PM
#2
Re: Time difference and time range
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
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?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 22nd, 2012, 09:25 PM
#3
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.
Last edited by fafalone; Dec 22nd, 2012 at 09:29 PM.
-
Dec 23rd, 2012, 07:22 AM
#4
Re: Time difference and time range
 Originally Posted by westconn1
which is the start and which is the stop time?
From the first post:
start time is 5:30 pm and the stop time is 6:00 am.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|