4
I am created a report to demonstrate the period of removal of employees, for that I need to calculate the days, months and years that the same stayed away, and I’m having a problem, in Firebird use something like datediff(day,dtini,dtfim)
, the problem is that if passed a period like 02/02/2014 and 02/02/2014 says there were 0 days of removal, a problem is that the datediff
returns me one day less.
Another problem is that I do not know a function in Firebird that returns periods in days, months and years, already considering the number of days of each month, leaving a margin of error in the calculation since I am making this calculation approximately.
2-2==0
, Isn’t it? To solve your problem isn’t just adding up1
to the Datediff result? And what do you mean by error margin? How do you want to use error margin in a subtraction account?– Math
01/12/2014 At 30/01/2015 - my result returns 2 months and 1 day understands! adding +1.I do not want to use error margin, I want to take the margin, as above
2-2==0 +1 =1
only that in some cases it adds an extra day +1– Balrog
It is two months of 31 days. One date less the other gives 60 days difference. How you arrived at the value of
2 meses
, Firebird itself does this conversion for you or you just split it by 30 to calculate how many months are?– Math
exemplifying again my problem, I need to calculate in a more "dynamic" way, because when it passes a month, I divide the value by 30, giving wrong values, because some months have 31 days, I tried to make a
if
checking whether the initial month is 31 days, but the calculation is wrong.– Balrog
Now I understand what you mean by the margin of error. I think there was a typo in your question, take a look at what I modified. By the way, are you working with some programming language together? For it can make this account of the difference of the days already considering the numbers of days of each month through the language itself, rather than using the bank for this.
– Math
@Balrog, I’ve run some tests here and there’s nothing unusual about the function
datadiff
, what seems to be strange is your logic, I do not know how you did it: "01/12/2014 At 30/01/2015 - my result returns 2 months and 1 day understands", because thisselect datediff (day, date '1-Dec-2014', date '30-Jan-2015') from rdb$database
, returns 60 days, so it’s correct, your problem seems to be converting days into years, months and days, right?– Fernando Leal
I’m working with Delhpi 7, and Firebird, but I have the following, it’s a report, the data is all in Firebird, yes the problem is in the conversion. the above example is one, but it may have long periods that I will need to calculate.
– Balrog
@Balrog You have the start date of the departure and the date of the departure and want to return via query how many days away the individual was, right? Will be considered months of 30 days or counting in days same?
– Caputo
@Caputo They will be considered months, when the days are greater than 30 I’m dividing by 30, I need to show the period that the individual was away as: 1 Year 2 Months and 25 days.
– Balrog