How to get the correct number of days of the months in a given year

If you try this:

you can see, the days of e.g. March are not correct because the daylight saving time has been changed here.

So try the following:

getDaysOfMonth.aia (11.8 KB)

grafik

2 Likes

Good work. But don't we really only need to check February? - assumes working with gregorian calendar - none of the other months change...

1 Like

Yes, but if it were to be calculated (for whatever reason) the decisive factor here is daylight saving time, which, as I have shown, would repeatedly lead to errors in the calculation.

For example, if you want to get the duration from this:

You are getting an incorrect duration ... (missing 3600000 millis).

You could do it like this:

but needs adjustment for December!

image

Ok, you create these dates, but there is no duration calculation.

By using the "day of the year" number, provided within the instant, you overcome any issues with DST (which is a PITA :smiley: )

Since these values simply return: 1, 2, 3, ... 364, 365.