How to write logic that will sum 2 variables

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
addisababa

How to write logic that will sum 2 variables

Post by addisababa »

I have two variables, Years & Months. I have already written logic to convert the years into months. But now, I would like to add the two to get the total number of months. How should I go about doing this?
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: How to write logic that will sum 2 variables

Post by Gregory Martin »

In general to sum two variables you simply use the + operator:
numeric monthsSince0AD = YEAR * 12 + MONTHS;
However, you might also want to look at the cmcode function. This function is useful for operations using dates. Another function datediff, is good if you want to do date comparisons when a day (in addition to month and year) is available.
Post Reply