Types of Operators
1. Add/Sub:
- If X and Y are integers or doubles then add or subtract the value of Y from X and if any X or Y is double then the result is double.
- If X is a date and Y is an integer then it returns a new date that is incremented or decremented by the specified number of days.
- If X s a DateTime and Y is an integer or double then it returns a new DateTime which is incremented or decremented by a specified number of days with a fractional portion corresponding to a portion of the day.
Ex: main() {
Double d = 5.2;
DateTime dt = new DateTime.now();
DateTime finalDate = dt -d ;
System.debug(dt);
System.debug(finalDate);
}
Note: Only in the case of ‘+’ if X is a string and Y is a string or any other type of non-null argument then it concatenates Y to the end of X.