in reply to Calculate the nearest day

Date::Calc and Date::Manip have the functions you need for this sort of thing. They account for just about everything under the sun in terms of things like leap seconds, leap years, other strange calendarial phenomena, the phase of the moon, and perhaps they might even determine what phase the spoon you're using to eat your cereal is in. Definatly what you want, but pick one and stick with it, I don't reccomend using them both in the same program as it becomes a headache later on. Or even both on the same box where applications might one day want to play nice.