Dealing with Midnight TimeValue

amaglam

New Member
Joined
Dec 11, 2020
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Hello, I am creating a tool where the user will running it for Day Shift and Night Shift about 15 minutes after the hour. The logic for Day Shift is fine, however, I just ran it after midnight and the date showed as todays date, as you would presume. The issue is that if a Night Shift manager wants to run it at 01:00, but they want to see data from the start of shift(19:00) then the date should be todays (date - 1) and after the column becomes >= 00:00 the start date should be todays date. My column headers are time value going from 17:00 to 05:00. Any help would be greatly appreciated.
VBA Code:
             Select Case intStartHour
                Case 19 To 22
                    If intCurrentHour < 7 Then
                        strStartDate = Format(Now - 1, "YYYY-MM-DD")
                        strEndDate = Format(Now - 1, "YYYY-MM-DD")
                    Else
                        strStartDate = Format(Now, "YYYY-MM-DD")
                        strEndDate = Format(Now, "YYYY-MM-DD")
                    End If
                Case 23
                    If intCurrentHour < 7 Then
                        strStartDate = Format(Now - 1, "YYYY-MM-DD")
                        strEndDate = Format(Now, "YYYY-MM-DD")
                    Else
                        strStartDate = Format(Now, "YYYY-MM-DD")
                        strEndDate = Format(Now + 1, "YYYY-MM-DD")
                    End If
                Case Else
                    strStartDate = Format(Now, "YYYY-MM-DD")
                    strEndDate = Format(Now, "YYYY-MM-DD")
                End Select
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
The issue is that if a Night Shift manager wants to run it at 01:00, but they want to see data from the start of shift(19:00)
The wording of that sentence implies that they could want to see data from the start of the shift, or from the middle.
Perhaps a Yes/No message box asking them if they want to run from start of shift for the time window where that could happen?
 
Upvote 0
It sounds like

VBA Code:
If (Now - Int(Now)) < TimeValue ("05:00:00") Then
    StartDate = Date - 1
Else
    StartDate = Date
End If
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top