[math] calculates the enclosed numerical, date, or time equation and displays the results. Any [xxx] variables are evaluated first, then the resulting equation is calculated. Standard algebraic order of operations are followed when evaluating expressions. Use parentheses to clarify or force a specific order of operations. To work with dates and times, put them inside curly-braces: {12/01/2010}. This converts them into numbers so they can be properly treated as numbers (more details in below).

Setting math variablesYou may also create up to 150 math variables by name. These named variables can be used in any other [math] context, or elsewhere in the page just like a text variable. When used within a math context, math variables do not need the square brackets. Otherwise they need the brackets, just like a text variable.

the name of a math variable is limited to 15 alphanumeric characters, and must begin with a letter.

When actually setting a math variable, the value will display, unlike a text variable. To prevent this, add show=f to the [math] context.

You can assign multiple math variables at the same time using a semicolon to separate the assignments. Example: [math show=f]var1=1;var2=2[/math].

In this example, some of the founditems are eliminated via the [hideif]. In this case, [index] and [numfound] would still include the eliminated items, and would not be useful to number the lines, nor to obtain a final count. The first line sets the initial value of [counter] to 0.

Date and Time MathDates included in mathematical expressions must be enclosed in curly braces. (You cannot mix both dates and times in one equation.) This converts them to a number (the number of days since 01/01/0000) so math can be performed. You may easily add or subtract days, months, or years from dates by expressing them in date format within curly braces. Just use 0 for values you want ignored. For instance, in order to add 2 months to today's date you would write: [math date]{[date]} {2/0/0000}[/math]. Then to redisplay the result back into date format, add the date modifier to the context, as indicated ([math date]). Note The year must be expressed as 4 digits.

Decimals in date notation: Some countries specify dates with decimal points, as in {10.1.2008}, but WebDNA will interpret this as a time instead. You can force it to interpret text as a Date by inserting a "D" in front of the text, as in [math]{D10.01.1998}[/math].

sometimes you want to calculate something without displaying the results, perhaps while calculating a running total. To do this, put "show=F" into the math parameters, as in [Math show=F]total=total [subTotal][/Math]. This allows you to perform calculations in the middle of a web page without the intermediate numbers appearing to the visitor. Later, you can show the value of the math variable with [math]total[/Math].

Historical behavior: Originally, a math variable had to be retrieved by using this format: [math]variablename[/math] (as opposed to [variablename]). It will still work this way. In fact, that is why seemingly incorrect code like [math]counter=counter 1[/math] works.

Time: The principles are the same for time, except the number represents seconds since midnight. Curly braces convert times into seconds since midnight, and using [math time] will display the result in time format.

Time may be included in mathematical expressions by enclosing the time in braces ( '{' and '}' ). You may easily add or subtract hours, minutes, or seconds from times by expressing them as a complete time. Use 0 for values that you want ignored. That is, in order to add 2 minutes to the current time you would write an expression like the following [math time]{[time]} + {00:02:00}[/math]. It is a good idea to group math expressions involving time together by using parentheses.

When using time mixed with integers, the final result is a value respresenting a number of seconds (e.g. {10:15:31} + 10 adds 10 seconds to the time). In fact, the result of a math expression with time is always the number of seconds. To display the output of the math expression as a time, add the Time modifier to the [math] context: [math time]...[/math].

you may use [format] to convert an integer number to a date or time. Use [Format Days_To_Date] and [Format Seconds_To_Time] to convert integer numbers to their equivalent dates/times. As already noted above, the integer number represents the number of days since January 1, 0000 and for time, the number of seconds since midnight.