Home      Ask a Question      My Stuff      Help   
  
Scripting - Creating a Split After a Set Amount of Hours
Scripting can split a punch based on a set number of hours using the "DATEADD" and "SPLIT" commands. The DATEADD command will be used to calculate the "time" the punch should be split.

SPLIT COMMAND
Just as a refresher, a very basic example of using the Split command, is:

split(7:00am);


USING DATEADD WITH THE SPLIT COMMAND
Since we want the script to calculate the time dynamically, we use:

split(Dateadd("h","4",intime));

With that example, if the employee's punch was 6:03am - 11:23am, the punch would be split at 10:03am. The Dateadd function, is interpreted as an actual time value to the scripting engine. To explain this command further, the parts of the Dateadd function are:

dateadd ( unit of time , number of units to add , a time value )

The valid units of time are:

H - Hour
N - Minute (that is an "n")
S - Second

The number of units to add can be a positive or negative number (it must be in quotes if it is negative, i.e. "-1"). The time value can be intime, outtime, or a specific time (like: 10:30pm).


USING A VARIABLE
Instead of using the Dateadd function directly, a made up variable can be used. For example:

MadeUpVariable = DateAdd("h",4,intime);
split(MadeUpVariable);

That will do exactly the same thing as:

split(DateAdd("h",4,intime));


AVOIDING MORE THAN ONE SPLIT
Keep in mind that when splitting time based on a calculation off the IN time, the "isfirsttoday" command is one way to keep the split from repeating. That will restrict this to only affect the first punch of the day (example below). Another option is to use a negative number calculated off the OUT time instead.

amount = DateAdd("h",1,intime);
if (isfirsttoday)
{
Split(amount);
}


EXAMPLES
-----
split(DateAdd("h","-1", 1:30pm)); //splits time at 12:30pm
-----
split(DateAdd("h","1", 1:30pm)); //splits time at 2:30pm
-----
MadeUpVariable = dateadd("n", "-30", outtime); //this assigns the time 30 minutes before the OUT punch to a variable.
ID
461
Category
<Unassigned>
Date Created
1/22/2010 11:28:54 AM
Date Updated
9/29/2016 4:54:05 PM
Back to Search Results