Most efficent way to adjust value I am working on a system that starts a process based of a set time value (startHour). The user sets the start hour and can only select values from 00-23. I have been asked to start the same process at 6 hour intervals so that it occurs 4 times during the day. 

My initial though is to add three more variable, secondStartHour, thirdStartHour and fourthStartHour. secondStartHour would be assigned a value 6 hours ahead of the startHour, thirdstartHour a value 12 hours ahead of startHour and fourthStartHour would be assigned a value 18 hours ahead of start hour. I could then use any of the startHour variables to trigger the process. 

I wrote some code (below) that will work but I'm wondering if there is a better, more efficient way of doing it. 

//set up secondStartHour 6 hours ahead of startHour
if (startHour &lt;= 5)
{
    secondStartHour = startHour - 18;
}
else
{
    secondStartHour = startHour + 6;
}

//set up thirdStartHour 12 hours ahead of startHour
if (startHour &lt;= 11)
{
    thirdStartHour = startHour - 12;
}
else
{
    thirdStartHour = startHour + 12;
}

//set up fourthStartHour 18 hours ahead of startHour
if (startHour &lt;= 17)
{
    fourthStartHour = startHour - 6;
}
else
{
    fourthStartHour = startHour + 18;
}


I had to write the code in the way I did above because I am working with a 24 hour clock so in some cases adding time to a startHour will actually reduce the value. By this I mean if startHour is 23 (23:00) and I need to add 6 hours to it to get secondStartHour the result will be 5 (05:00) so I can't simply write code to say secondStartHour = startHour + 6. The code just seems too long winded and messy but I cant think of a better way to write it. I could use a switch case statement but then I would have 24 cases with assignments for each of the new variables in each case so that seems worse, any ideas would be appreciated.
Instead of comparing, you can use the modulo operator:

 secondStartHour = (startHour +  6) % 24;


And similar for the others:

 thirdStartHour  = (startHour + 12) % 24;
 fourthStartHour = (startHour + 18) % 24;


While xxxStartHour >= 24, 24 will be removed until it is within range [0, 24).

If you need an offset, you also can add some hours of course after the module (I don't fully understand your example which can have values >= 24.

Also, if you need to do the same task every 6 hours, you can use with one time and 'restart' it every 6 hours (and maybe taking summer/winter time into account).