Qdabra Forms - qRules Command Guide Every qRules command, its parameters and behavior All manuals

Chapter 4 - Dates and numbers

First draft. This chapter has not been reviewed yet and may contain mistakes. Please read it with that in mind, and tell us about anything that does not match what you see.

These eight commands calculate with dates and format dates and numbers: add time or working days to a date, measure the difference between two dates, find a weekday or the day of the year, turn a date or number into display text, and compute the internal rate of return and net present value of a series of cash flows. Chapter 1 explains the command syntax, dynamic parameter values and where results go; this chapter assumes you know it.

The examples use this main data source:

my:myFields
  my:StartDate          (date)
  my:EndDate            (date)
  my:SubmittedOn        (dateTime)
  my:DueDate            (date)
  my:Amount             (decimal)
  my:DiscountRate       (decimal, for example 0.08)
  my:CashFlowList       (text, for example -1000,300,400,500)
  my:Holidays
    my:Holiday          (date, repeating)

How the date commands read dates. DateAdd, DateDiff, GetDayOfYear and GetWeekDay expect the value as it is stored in a date or dateTime field: YYYY-MM-DD, or YYYY-MM-DDThh:mm:ss (seconds and fractions of a second are optional). They do no time zone conversion: the date and time are used exactly as written, a Z at the end is ignored, and daylight saving changes have no effect on the arithmetic. Use values without a time zone offset. A display value such as 10/9/2026 is not a valid date for these commands.

4.1 DateAdd

Adds (or subtracts) seconds, minutes, hours, days, working days, weeks, months or years to the date in a field and returns the new date. Use it for due dates, reminders and deadlines, including deadlines in business days that skip weekends and holidays.

Syntax

DateAdd /xpath=<XPath> [/dsname=<data source>] [/seconds=<n>] [/minutes=<n>] [/hours=<n>] [/days=<n>] [/weekdays=<n>] [/weeks=<n>] [/months=<n>] [/years=<n>] [/xpathhol=<XPath> [/dsnamehol=<data source>]]
Parameter Required Description
/xpath Yes The date or dateTime field to start from. Only the first match is used. The field itself is not changed.
/dsname No Data source of that field. Omit for the main data source.
/seconds At least one of these Seconds to add. A negative number subtracts.
/minutes At least one of these Minutes to add or subtract.
/hours At least one of these Hours to add or subtract.
/days At least one of these Calendar days to add or subtract.
/weekdays At least one of these Working days to add or subtract: Saturdays, Sundays and the holidays in /xpathhol are skipped.
/weeks At least one of these Weeks (7 days each) to add or subtract.
/months At least one of these Months to add or subtract.
/years At least one of these Years to add or subtract.
/xpathhol No Only with /weekdays. XPath to a repeating field (or a field in a repeating group) that lists holiday dates to skip.
/dsnamehol No Data source of the holiday list. Omit for the main data source.

Result: the new date. If the field holds a date only, the result is YYYY-MM-DD; if it holds a date and time, the result is YYYY-MM-DDThh:mm:ss.

Examples

DateAdd /xpath=/my:myFields/my:StartDate /days=30 /resultxpath=/my:myFields/my:DueDate
DateAdd /xpath=/my:myFields/my:SubmittedOn /hours=-8
DateAdd /xpath=/my:myFields/my:StartDate /weekdays=5 /xpathhol=/my:myFields/my:Holidays/my:Holiday
DateAdd /xpath=/my:myFields/my:StartDate /weekdays=10 /dsnamehol=CompanyHolidays /xpathhol=/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:HolidayDate

The first example writes a due date 30 days after the start date. The third returns the date five working days after the start date, skipping weekends and the dates in the form's holiday table; the fourth does the same with a holiday list from a SharePoint list data source named CompanyHolidays.

Notes

Related: DateDiff, GetWeekDay, SetValue.

4.2 DateDiff

Calculates the difference between two dates: in whole days, in working days (with optional holidays), as one part (hours, minutes, ...) of the difference, or as a total in days, hours, minutes, seconds or milliseconds.

Syntax

DateDiff /date1=<date> /date2=<date> [/component=<component>] [/xpathhol=<XPath> [/dsnamehol=<data source>]]
Parameter Required Description
/date1 Yes A date value. The result is /date1 minus /date2. Usually given as /date1-xpath= to read a field.
/date2 Yes The date to subtract from /date1. Usually given as /date2-xpath=.
/component No What to return. Default weekdays. See the table below.
/xpathhol No Only with /component=weekdays. XPath to a repeating field (or a field in a repeating group) that lists holiday dates to exclude.
/dsnamehol No Data source of the holiday list. Omit for the main data source.
Component Short form Returns
days d Whole days, rounded down.
weekdays Monday to Friday days, minus holidays.
hours h The hours part of the difference (0 to 23).
minutes m The minutes part (0 to 59).
seconds s The seconds part (0 to 59).
milliseconds ms The milliseconds part (0 to 999).
totaldays td The whole difference in days, with decimals.
totalhours th The whole difference in hours, with decimals.
totalminutes tm The whole difference in minutes.
totalseconds ts The whole difference in seconds.
totalmilliseconds tms The whole difference in milliseconds.

Result: a number. It is positive when /date1 is later than /date2.

Examples

DateDiff /date1-xpath=/my:myFields/my:EndDate /date2-xpath=/my:myFields/my:StartDate /component=days
DateDiff /date1-xpath=/my:myFields/my:EndDate /date2-xpath=/my:myFields/my:StartDate /component=weekdays /xpathhol=/my:myFields/my:Holidays/my:Holiday
DateDiff /date1=2026-10-09T17:30:00 /date2=2026-10-08T09:00:00 /component=totalhours

The first returns the number of calendar days between the two dates; the second the number of working days, excluding the holidays in the form. The third returns 32.5; with /component=days, hours and minutes the same two values return 1, 8 and 30.

Notes

Related: DateAdd, GetDayOfYear.

4.3 FormatDate

Turns a date into display text, such as October 9, 2026 or 09-Oct-2026, for use in a text field, a file name or an e-mail. It uses .NET standard and custom date and time format strings.

Syntax

FormatDate /date=<date> [/format=<format string>]
Parameter Required Description
/date Yes The date or date and time to format. Usually /date-xpath= pointing to a date field.
/format No A .NET standard format (one letter, such as d) or a custom format (such as yyyy-MM-dd). Default d, the short date pattern.

Result: the formatted text. Success is false if the date cannot be formatted.

Examples

FormatDate /date-xpath=/my:myFields/my:StartDate /format=MMMM d, yyyy
FormatDate /date-xpath=/my:myFields/my:SubmittedOn /format=yyyyMMdd-HHmm
FormatDate /date-xpath=/my:myFields/my:StartDate /format=dddd

For a start date of 2026-10-09, the first returns October 9, 2026 and the third Friday (with English month and day names). The second builds a sortable stamp such as 20261009-1730 for a file name.

Notes

Related: FormatNumber, DateAdd.

4.4 FormatNumber

Turns a number into display text with a .NET standard or custom numeric format: thousands separators, a fixed number of decimals, currency, percent, leading zeros. Optionally, a culture sets the separators and currency symbol.

Syntax

FormatNumber /value=<number> /format=<format string> [/culture=<culture name>]
Parameter Required Description
/value Yes The number to format. Usually /value-xpath= pointing to a number field.
/format Yes A .NET standard format (such as N2, C, P1, D6) or a custom format (such as #,##0.00 or 000000).
/culture No A .NET culture name, such as en-US, de-DE or ja-JP, that controls the decimal and thousands separators and the currency symbol. Omit it to use the default.

Result: the formatted text. Success is false if the number cannot be formatted.

Examples

FormatNumber /value-xpath=/my:myFields/my:Amount /format=N2
FormatNumber /value-xpath=/my:myFields/my:Amount /format=C /culture=en-US
FormatNumber /value-xpath=/my:myFields/my:Amount /format=N2 /culture=de-DE
FormatNumber /value=0.0825 /format=P2

For an amount of 1234.5, the first returns 1,234.50, the second $1,234.50 and the third 1.234,50. The last returns 8.25 % or 8.25%, depending on the culture.

Notes

Related: FormatDate.

4.5 GetDayOfYear

Returns the day number within the year (1 to 366) for a date, or for today. Useful for sequence numbers, Julian-style date codes and lot numbers.

Syntax

GetDayOfYear [/date=<date>]
Parameter Required Description
/date No The date. If the parameter is left out, today's date (on the user's computer) is used.

Result: the day number, from 1 for January 1.

Examples

GetDayOfYear
GetDayOfYear /date-xpath=/my:myFields/my:StartDate

The first returns today's day number. For a start date of 2026-10-09, the second returns 282; 2024-12-31 returns 366.

Notes

Related: GetWeekDay, DateDiff.

4.6 GetWeekDay

Returns the date of a given weekday in the same week as a date. Weeks run from Sunday to Saturday. Use it to find the week-start (Sunday or Monday) or week-ending (Friday or Saturday) date for a timesheet or weekly report.

Syntax

GetWeekDay /day=<day> [/date=<date>]
Parameter Required Description
/day Yes The weekday to return: the full English name (monday) or its first two letters (mo, tu, we, th, fr, sa, su). Not case-sensitive.
/date No Any date in the week. If omitted or empty, the current date is used.

Result: the date of that weekday, as YYYY-MM-DD.

Examples

GetWeekDay /day=su /date-xpath=/my:myFields/my:StartDate
GetWeekDay /day=saturday /date-xpath=/my:myFields/my:StartDate /resultxpath=/my:myFields/my:DueDate
GetWeekDay /day=mo

For Friday 2026-10-09, the first returns Sunday 2026-10-04 and the second Saturday 2026-10-10. The third returns the Monday of the current week.

Notes

Related: GetDayOfYear, DateAdd.

4.7 Irr

Returns the internal rate of return for a series of periodic cash flows (payments as negative numbers, receipts as positive numbers). Use it in investment, capital request and business case forms.

Syntax

Irr /values=<n>,<n>[,<n>...] [/guess=<rate>]
Parameter Required Description
/values Yes The cash flows, in period order, separated by commas. At least one must be negative and at least one positive.
/guess No Your estimate of the rate, as a decimal fraction. Default 0.1 (10 percent).

Result: the internal rate of return, calculated by Qdabra Forms.

Example

Irr /values=-1000,300,400,500
Irr /values-xpath=/my:myFields/my:CashFlowList /guess=0.05

The first describes an investment of 1000 followed by three receipts; its internal rate of return is about 8.9 percent. The second reads the list from a text field.

Notes

Related: Npv, FormatNumber.

4.8 Npv

Returns the net present value of a series of periodic cash flows at a given discount rate.

Syntax

Npv /rate=<rate> /values=<n>,<n>[,<n>...]
Parameter Required Description
/rate Yes The discount rate per period, as a decimal fraction (for example 0.08 for 8 percent).
/values Yes The cash flows, in period order, separated by commas. At least one must be negative and at least one positive.

Result: the net present value, calculated by Qdabra Forms.

Example

Npv /rate=0.08 /values=-1000,300,400,500
Npv /rate-xpath=/my:myFields/my:DiscountRate /values-xpath=/my:myFields/my:CashFlowList

The first discounts the four cash flows at 8 percent per period; the second takes the rate and the list from fields.

Notes

Related: Irr, FormatNumber.

Back to the Command Index.

© Qdabra Software  |  Questions and corrections: [email protected]  |  Preview copy, not linked from the public site.