It's wrong. It's an approximation that assumes every month has 30 days.
Or in more simple terms (from Wikipedia):
if (year is not exactly divisible by 4) then (it is a common year)
else
if (year is not exactly divisible by 100) then (it is a leap year)
else
if (year is not exactly divisible by 400) then (it is a common year)
else (it is a leap year)
Of course, this only applies to Gregorian calendars, which we use today... :-)
And BTW, years != month/12, unless you are talking about the total number of months beyond or == 12, so you should say:
(months~=total_days/30;), (years=total_months/12;), (day_of_the_month~=total_days%30). Remember the approximate symbol (~). Approximations are good, if you remember to note them, otherwise you are just plain wrong!
//Hint:
//Do you know what modular arithmetic (here, division) means?
//If you have these next two integers stored in 'a' and 'b':
int a = 23;
int b = 10;
// Do you know what values the following x, y would hold?
int x = a / b ;
int y = a % b ;
// if not,
// study (do a web search on)
// 'integer division'
// and also
// 'modular division'.
Per David W's post, modular arithmetic returns the remainer of a division operation, so 4%2 is the remainder of 4/2 which is 0. If there are 30 days in a month, then if it is the 15th of the month, the remainder of 15/30 is 15, so 15%30 == 15. If we are using the day of the year to determine the month, and day of the month, assuming all months have 30 days, then if the day is 250, the month is 250/30 == 8 with a remainder of 10. So 250%30 == 10. IE, the date would be the 10th of the 9th month (September 8th) as the 8th month (August) is complete.