title: Want to Check for a GivenDate(GivenTime "Condition" RuleTime) in Excel VBA
body: <p>I'm working for a payroll system for my client and they have multiple business rules.</p>
  <p>There are weekday, saturday, sunday/Hoilday rules applicable. Day shift starts at 06:00 and ends at 22:59 for a given date. Night shift starts from 23:00 of present date and ends at 05:59 of next day morning.</p>
  <p>Say a employee starts working at 22:00 on Friday and ends his work on 10:00 at Saturday. For this given example,</p>
  <ol>
  <li>employee works 00:59 hours in Friday - Day shift which is from 22:00 to 22:59</li>
  <li>Employee works 6:59 hours in Friday - Night shift which is from 23:00(friday) to 5:59(saturday)</li>
  <li>Employee works 04:00 hours in Saturday - Day shift which is from 06:00 to 10:00</li>
  </ol>
  <p>I want to split this time as Weekday - DayTime and NightTime and also Saturday - DayTime</p>
  <p>I'm working on VBA code to find logic for this.</p>
  <p>MyCode:</p>
  <pre><code>StartDateReturnValue = Weekday(startDate, vbSunday)
  endDateReturnValue = Weekday(endDate, vbSunday)
  
  'Same Day: Start time and End time is NIGHTTIME
  If endDateReturnValue = StartDateReturnValue + 1 And TimeValue(startTime) &gt;= TimeValue(&quot;23:00:00&quot;) And TimeValue(endTime) &lt;= TimeValue(&quot;05:59:00&quot;) Then
  </code></pre>
  <p>I want something like this to be very specific</p>
  <pre><code>StartWorkday(Timevalue(startTime)&gt;=TimeValue(&quot;22:59:00&quot;)) And EndWorkday(Timevalue(endTime)&lt;=TimeValue(&quot;05:59:00&quot;))
  </code></pre>