Suppose I have the function $f(x)= x^2$ which accounts for the population growth of ants in an area, where x is any given day. At day 1, there is 1 ant. Day 2, 4 ants. Day 3, 9 ants. Day 4, 16 ants. I assume that the integral of this function would be the total amount of ants. However, when I compute the integral at x = 2, I get the number 8/3 which doesn’t make sense, since there are 4 ants in day 2. So that means my assumption is wrong.
In this case, then, what does the integral mean?
Now I have another case. Suppose that the total amount of sunlight on any day d (where 0 is the start of the year and 2 $\pi$ is the last day of the year) is sin(t) + 12. Suppose I have a solar panel that produces 300 watts of energy per hour of sunlight. If I want to compute the total amount of energy produced by the solar panel in a year, is it appropriate to calculate the total hours of sunlight by computing the integral of the function?
The broader question is, in what set of cases is it appropriate to use an integral to solve a problem.
The problem with using integration in your first example is that the function is discrete. For the whole of day $1$, the population of ants is $1$; for the whole of day $2$, the population of ants is $1+4=5$, and so on. What you would have to integrate to get the correct result is a discrete function $f(x)$, such that $f(x) = 0$ for $-1 ≤ x < 0$, $f(x) = 1$ for $0 ≤ x < 1$, $f(x) = 4$ for $1 ≤ x < 2$ and so on.
For your second example, the case is the same. Because the total amount of sunlight is only given for each day $d$, and not for all the times in the year, then using integration will not give the correct result. Since the number of summations is large ($365$ days), this will give a good approximation for the total hours of sunlight, but unless the number of summations tends to infinity (every second, every millisecond, every nanosecond etc.), the answer will still be slightly different from the integral, but the difference will be insignificant.
Integration is only useful when the function you are trying to integrate is continuously changing. Calculus in general is all about change: finding the slope and the area when the function does not change linearly. For discrete functions, we have to use summations instead.
However, integrals and summations are somewhat closely related. There are many tricks we can use to approximate summations as integrals or vice versa (such as swapping the order of the integral and summation). This is useful as we can use integration to approximate sums of powers (such as the sum of cubes, $1^3+2^3+3^3+\cdots+n^3$), which can lead us to an accurate formula as shown in Mathologer's video but this is beyond the scope of this question.