Calculation depends if it is a leap year

Hello,

I have following calculations : amount*number_of_days_in_a_month / number_of_days_in_a_year.

I don’t know to to introduce into calculation a leap year (29 days for February and 366 days if it is a leap year and 28 days for February and 365 days in a year if it is a normal year.

I have a column with indication of a year
I created a table where I wrote how many days are in a month (31 days for January…31 days for February).

I will appreciate any help!

Hi @Skirpichnikova_Ksenia,
I would recommend checking this by using the Date&Time Difference node. For the year, calculate the number of days from 1.1. to 1.1.<year+1> and for the month so it in a similar fashion. The String to Date&Time and Extract Date&Time Fields nodes comes in handy here as well.
Kind regards,
Alexander

1 Like

hi, Alexander, many thanks for answering. Could you please give more details? I can’t get what “calculate the number of days from 1.1. to 1.1.<year+1>” can practically mean?

year amount month calculation
2020 100 February =B2*29/366
2020 120 March =B3*31/366
2020 123 April =B4*30/366
2020 130 May =B5*31/366
2021 100 February =B6*28/365
2021 120 March =B7*31/365
2021 123 April =B8*30/365
2021 130 May =B9*31/365

Hi @Skirpichnikova_Ksenia

you can calculate all with Date&Time Difference node see example.

Example

BR

1 Like

hi, data will be updated on a monthly basis and the end user will not have access for a workflow. I don’t think that creating a Date&Time Difference node.

Hi,
if you know the year and the month of your data you can generate the necessary dates within you workflow.

BR

hi, do you know how I can make calculation I want to do? )

Hi,
can you upload an example file with data?

hi, I have shared the example above but can repeat it here with one modification:

year amount month calculation calculation2
2020 100 February =B2*10/366 =B2*(29-10)/366
2020 120 March =B3*10/366 =B2*(31-10)/366
2020 123 April =B4*10/366 =B2*(30-10)/366
2020 130 May =B5*10/366 =B2*(31-10)/366
2021 100 February =B6*10/365 =B2*(28-10)/366
2021 120 March =B7*10/365 =B2*(31-10)/366
2021 123 April =B8*10/365 =B2*(30-10)/366
2021 130 May =B9*10/365 =B2*(31-10)/366

Hi,
the answer is my screenshot. You need the Date&Time Difference Node and prior to the Node specific Date calculations based on your data record. This are for the days of month calculation the 1st of the current month and 1st of the next month (see Row1 or Row 3) respecticely for the year calculation the 1st of january of the current year and the 1st of january of the next year.
To get these dates you can solve it using different nodes or solve it with one java snippet node.

Final solution : I used column expression and if–else to identify number of days in a year and number of days in a month

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.