| xHarbour Reference Documentation > Operator Reference |
![]() |
![]() |
![]() |
Plus operator: add values, concatenate values and unary positive.
<nNumber1> + <nNumber2> <dDate> + <nNumber> <dDateTime> + <nNumber> <cString1> + <cString2> <hHash1> + <hHash2>
Depending on the data types of the operands, the Plus operator performs different operations.
Unary positive sign
A numeric expression preceeded by the "+" operator performs no operation on the operand.
Numeric addition
When both operands are numeric values, the right operand <nNumber2> is added to the left operand <nNumber1> and the result is a numeric value.
Date addition
When either operand is a date value and the other is a numeric, the value of <nNumber> is added as days to <dDate>. The returned value is a date.
DateTime addition
When either operand is a DateTime value and the other is a numeric, the value of
<nNumber> is added as days to <dDateTime>. The result is a DateTime value.
To add hours or minutes, the numeric operand must be coded as fraction of
a day. E.g. <dDateTime> + 1/24 adds one hour to <dDateTime>
(refer to the DateTime operator ).
String concatenation
If both operands are character strings, the value of <cString2> is joined
to the end of <cString1>. The result is a character string containing both
operands.
Hash operation
If both operands are hashes, a set-oriented operation is performed so that
the resulting hash value contains unique keys of both operands
(refer to the hash operator ).
Info
| See also: | %, *, **, ++, -, /, = (compound assignment), {=>}, {ˆ } |
| Category: | Character operators , Mathematical operators , Operators |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example demonstrates variations with the + operator:
PROCEDURE Main
// Unary positive sign (also included is the negative sign)
? 1 + + 1 // result: 2
? 1 + - 1 // result: 0
? 1 - - 1 // result: 2
// Addition
? 10 + 2 // result: 12
? CtoD("01/01/2005") + 5 // result: 01/06/2005
? 31 + CtoD("01/01/2005") // result: 02/01/2005
? {ˆ 2007/04/26 15:30:00 } // result: 04/26/07 15:30:00.00
? {ˆ 2007/04/26 15:30:00 }+1 // result: 04/27/07 15:30:00.00
? {ˆ 2007/04/26 15:30:00 }+1/24 // result: 04/26/07 16:30:00.00
? {ˆ 2007/04/26 15:30:00 }+1/86400 // result: 04/26/07 15:30:01.00
// String concatenation
? "Visit" + " " + "xHarbour.com" // result: "Visit xHarbour.com"
RETURN
http://www.xHarbour.com