In my table
If I use 365.25 (which is the "real" number of days in a year), it does not work either.
subventions
(grants), I created a trigger to be able to calculate the annual amount of money of a grant, using my columns subventions.début
(beginning), subventions.fin
(end) and subventions.montant
(amount).
As DATEDIFF
only gives me an answer in days, I naively thought that I only had to divide it by 365 days to obtain my answer. It works if my beginning date is the first of january and the end date the 31st of December, but does not if it stars somewhere else during the year. Here is my trigger:
SET NEW.montant_annuel = NEW.montant / (datediff(NEW.fin,NEW.début)/365)
Here is my table and the result in the 'montant_annuel' column:

Asked by MDF
(113 rep)
Aug 28, 2015, 04:43 PM
Last activity: Jun 1, 2025, 09:01 PM
Last activity: Jun 1, 2025, 09:01 PM