int = TithiNumberOf(nWesternDate, nMoonSourceIndex, bSecondTithiIfExists)
This macro function returns the number, from 1 to 30, of the first or second tithi beginning on nWesternDate, using the Moon data source of index nMoonSourceIndex.
If the requested occurrence does not fall on that date, the function returns -1.
Set bSecondTithiIfExists to false to request the first tithi beginning on the date, or true to request the second. If only one tithi begins on the date, requesting the second returns -1. If none begins on the date, both requests return -1.
Leap and expunged days
Hindu calendars can repeat a lunar day number on consecutive calendar days (a leap day such as 5 followed by 5), or skip a lunar day number (an expunged day, such as 5 followed by 7). These functions report tithi beginnings within the civil date, from midnight to midnight. Their results should therefore be distinguished from the assignment of lunar day numbers according to the calendar’s reference time.
Example
The macro code below checks if a date is the date of the Deepavali holiday of southern India (there are a few more subtleties in the actual calculation, but the code below gives the gist of it).
bIsDeepavali = false
nCurTithiNumber = TithiNumberOf(n_TokenDate, 1, false)
nCurTithiTime = TithiTimeOf(n_TokenDate, 1, false)
nCurSunrise = SunRiseSetTimeOf(n_TokenDate, 1, 1)
if (nCurTithiTime >= 0) and (nCurSunrise >= 0)
switch nCurTithiNumber
case 29
bIsDeepavali = (nCurSunrise > nCurTithiTime)
case 30
bIsDeepavali = (nCurSunrise < nCurTithiTime)
else
bIsDeepavali = false
endswitch
endif
For this example, Sun data source 1 and Moon data source 1 must refer to the intended location and use consistent local-time settings. The comparison is made only when both the requested tithi beginning and sunrise are present. If either is absent, the example leaves bIsDeepavali false; this is not a complete holiday rule for such cases.
See also: TithiTimeOf, SunRiseSetTimeOf.
Topic 179710, last updated on 14-Oct-2026