All Collections
Payroll(HK)
How to value and calculate the date in the payroll calculation formula?
How to value and calculate the date in the payroll calculation formula? Written by Workstem CS
Updated over a week ago

In the process of payroll calculation, some pay items need to be calculated to value the employee’s start/end date of attendance, start/end date of payroll calculation period, and date of pay day, then calculate the difference of days/months/years between these start and end dates.

Workstem provides relevant functions:

DateDiff( , , ,), DateAdd( , , ,), PayRunCycleStartDate(), PayRunCycleEndDate(), PayRunAttendStartDate(), PayRunAttendEndDate(), PayRunPayDate().

In the calculation of pay items, you can flexibly use such functions. The use of these functions is described in detail below:

## Step 1

[Payroll] > [Settings] > [Pay Items] > [Settings]

## Step 2

Click [Settings], go to [Pay Items], find the corresponding item that needs to set the formula, click [Formula], or add new item to formula setup step, and go to [Pay Items] formula setting interface.

## Step 3

1. Functions DateDiff(Date Part, StartDate, EndDate,), PayRunCycleStartDate() , PayRunCycleEndDate()

a. DateDiff(Part, StartDate, EndDate)

Function description: Calculate the time difference between two specified dates

Parameter list:

Optional range of Date Part: DAY / MONTH / YEAR

Format of StartDate/EndDate: YYYY-MM-DD

Example:

// The result is 364

var c = DateDiff (DAY, '2019-01-01', '2019-12-31')

// The result is 11

var d = DateDiff (MONTH, '2019-01-01', '2019-12-31')

b. PayRunCycleStartDate()

Function description: Return the start date of the current payroll calculation period

No parameter

Example:

// If the current payroll calculation period is 2020-03-01 to 2020-03-31.

The result is 2020-03-01

var b = PayRunCycleStartDate()

c. PayRunCycleEndDate()

Function description: Return the end date of the current payroll calculation period

Method: PayRunCycleEndDate ()

No parameter

Example:

// If the current payroll calculation period is 2020-03-01 to 2020-03-31.

The result is 2020-03-31

var a = PayRunCycleEndDate ()

2. Functions DateAdd(Part, number, Date), PayRunAttendStartDate(), PayRunAttendEndDate()

Function Description: Calculate a specific date

Parameter Description:

Optional range of Date Part: DAY / MONTH / YEAR

Date: Full date YYYY-MM-DD

Number：Integer, the value of date calculated forwards (positive number) or backwards (negative number)

Example:

// The result is 2019-12-15

var a = DateAdd (DAY, -5, '2019-12-20')

// The result is 2020-05-20

var b = DateAdd (MONTH, 5, '2019-12-20')

b. PayRunAttendStartDate()

Function description: Return the start date of attendance period used in the current payroll calculation period

No parameter

Example:

// If the attendance time used in the current payroll calculation period is 2020-03-01 to 2020-03-31.

// The result is 2020-03-01

var c = PayRunAttendStartDate ()

c. PayRunAttendEndDate()

Function description: Return the end date of attendance period used in the current payroll calculation period

No parameter

Example:

// If the attendance time used in the current payroll calculation period is 2020-03-01 to 2020-03-31.

The result is 2020-03-31

var d = PayRunAttendEndDate ()