xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

-

Minus operator: add values, concatenate values and unary negative.

Syntax

<nNumber1> - <nNumber2>
<dDate1> - <dDate2>
<dDate> - <nNumber>
<dDateTime> - <nNumber>
<cString1> - <cString2>
<hHash1> - <hHash2>

Arguments

<nNumber1>
<nNumber1> is a numeric value from which the value of <nNumber2> is subtracted.
<dDate1>
<dDate1> is a date value from which the date value <dDate2> is subtracted.
<dDate>
<dDate> is a date value from which <nNumber> days are subtracted.
<dDateTime>
<dDate> is a DateTime value from which <nNumber> days are subtracted.
<cString2>
<cString2> is a character string to add to the end of <cString1> after all trailing blanks from <cString1> are removed.

Description

Depending on the data types of the operands, the Minus operator performs the following operations:

Unary negative sign

when the Minus operator precedes a numeric operand, it performs the equivalent of multiplying the operand by -1. This changes the operand's sign from plus to minus and vice versa.

Numeric subtraction

When both operands are numeric values, the right operand <nNumber2> is subtracted from the left operand <nNumber1> and the result is a numeric value.

Date subtraction

When the left operand is a date value and the right operand is a numeric, the value of <nNumber> is subtracted as number of days from <dDate>. The returned value is a date.

When both operands are of Date data type, the operator calculates the difference in days between left and right operand and returns a numeric value.

When the left operand is a Numeric value and the right operand is a Date, a runtime error is raised since this is not allowed.

DateTime subtraction

When the left operand is a DateTime value and the right operand is a numeric, the value of <nNumber> is subtracted as number of days from <dDateTime>. The returned value is a date. To subtract hours or minutes, the numeric operand must be coded as fraction of a day. E.g. <dDateTime> - 1/24 subtracts one hour from <dDateTime> (refer to the DateTime operator ).

When both operands are of DateTime data type, the operator calculates the difference in days between left and right operand and returns a numeric value.

When the left operand is a Numeric value and the right operand is a DateTime, a runtime error is raised since this is not allowed.

String concatenation

If both operands are character data types, the value of <cString2> is joined to <cString1>, returning a character string. Trailing blanks in <cString1> are removed and appended to the end of the result string.

Hash operation

If both operands are hashes, a set-oriented operation is performed so that the resulting hash value contains unique keys of the left operand which are not contained in the right operand (refer to the hash operator ).

Info

See also:%, *, **, +, --, /, = (compound assignment), {=>}, {ˆ }
Category: Character operators , Mathematical operators , Operators
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates variations with the - operator:

   PROCEDURE Main
      // Unary negative sign (also included is the positive sign)
      ? 1 - - 1                        // result: 2
      ? 1 + - 1                        // result: 0
      ? 1 + + 1                        // result: 2

      // Subtraction
      ? CtoD("01/20/2005") - 5         // result: 01/15/2005
      ? 10 - 2                         // result: 8

      ? {ˆ 2007/04/26 15:30:00 }          // result: 04/26/07 15:30:00.00
      ? {ˆ 2007/04/26 15:30:00 }-1        // result: 04/25/07 15:30:00.00
      ? {ˆ 2007/04/26 15:30:00 }-1/24     // result: 04/26/07 14:30:00.00
      ? {ˆ 2007/04/26 15:30:00 }-1/86400  // result: 04/26/07 15:29:59.00

      // String concatenation
      ? "A " + "B " + "C "             // result: "A B C "
      ? "A " - "B " - "C "             // result: "ABC   "
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe