How can I calculate the last possible time to say Kiddush Levanah for a given month?
The first step of the calculation is finding out the Molad of that month. The molad can be found by looking at a local hebrew calendar. One important thing to note is that the molad is usually quoted in Jerusalem solar time (which is Universal Time + 2h 20m 56s, or approx. +2h 21m). So for example, for Sivan 5770, the molad is on May 13th, at 4:39pm and 15 Chalakim, Jerusalem Solar time. However, depending on your location, you may need to add or subtract the difference to adjust the Molad to your timezone. For example, in NY the molad would be 7 hours and approximately 21 minutes earlier, or at May 13, at 9:18am [for the sake of simplicity I'm dropping Chalakim]. The time differences may also fluctuate based on daylight savings time, so keep that in mind.
There are multiple shitos for the last time to say kiddush levanah:
Some hold (including the rema) that the latest time is at the halfway point between two moladim, or 14 days, 18 hours and ~22 minutes after the molad. So for this method simply add those measurements to the molad time we found above. For Sivan 5770, it would be at May 28, 3:40am.
The next shitah is quoted by the mechaber at a full 15 days. So adding 15 days to the molad, gives the correct timeframe. For Sivan 5770, it would be at May 28, at 9:18am.
As far as which shitah you should use: that is up to your local Posek. Obviously, the first shitah is included in the second, and as such is held by all poskim.
Also note that Kiddush Levanah can only be said at night, so if the end time is during the day, one can only say it the night before.
(I happen to use this calculation to power the reminder at http://www.tizkor.com/kiddush)