Arithmetic with Dates

Search for answers or browse our knowledge base.

< All Topics

ZIM-X provides a number of built-in functions to perform date and time arithmetic.  If an arithmetic expression subtracts one date from another (i.e., both operands are of data type DATE), the result is a number representing the number of days between the two dates.


Consider the Date Type values: Date1 = 19990923 (23SEP1999) and Date2 = 19980923 (23SEP1998).  We can now apply arithmetic to the dates by simply doing the following:

Date1 – Date2 evaluates to 365. Because the numbers are Date Types, ZIM equates to Date1 to 19990923 and Date2 to 19980923. If the same calculation was performed with INT Data Types the result would be 10,000.

If you add (subtract) a value that is not a date to (from) a date, the result is a date equal to the date operand plus (minus) the number of DAYS indicated by the non-date operand.

Date1 - 100 equates to 19990923 - 100, but evaluates to 19990615 (15Jun1999 - not 19990823)
Date1 + 100 equates to 19990923 + 100, but evaluates to 20000101 (1Jan2000- not 19991023)


You can covert a Number Type value to do a Date Type value by using $todate().

If you use dates in any other type of operation, the dates are treated as numbers:

Date1/100 equates to 19990923/100, and evaluates to 199909.

See Also





Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.

Leave a Reply

Your email address will not be published. Required fields are marked *