Need help with date conversion

I need help to convert my dates such as week, month and year
ex: (1 month = 4 weeks, 1 year = 12 months) also if week is greater than 4, add 1 month and week input go back to zero, same if months is greater than 11 add 1 year and set months back to zero

ex:
timespan = 2 month 3 weeks:
desired input result = 3 weeks / 2 months / 0 years

timespan = 1 month 1 year:
desired input result = 0 weeks / 1 months / 1 years

I’m sure there are many ways to do this, especially if using plugins or javascript. One way I can think of that doesn’t do that is to start by calculating the total number of days in your date range. You can do that like this: date 2- date1:formatted as days. Once you have the total number of days you can perform various operations to calculate the years, months, and days. For example, if days >=365, then Years = days/365:floor. Then use the modulo operator to perform similar operations for months and then weeks

1 Like

Yes i did all basic calculations already, what i need to know is how to use these modulo operators to set my weeks back to zero once it reaches a month or 4 weeks+, same for months once it reaches a year

You don’t need to set anything back to zero if you start with the highest timespan first and work your way down the chain (for example, calculate years then with the modulo calculate months, then with the modulo calculate weeks). Do you have a specific question about the modulo operator?

im not familiar with modulo, can you send me a public example?
also my goal is to have 3 inputs with week, month and year.
but each input cannot exced its maximum value, week max = 7days, month max = 12 months and so on, thats why im telling about zero the value once it reaches max

ex: if the number of weeks exceed 4, add 1 to months, past that recaulculate the weeks starting from zero again

for now im using this formula to acchieve that: (weeks)-(months*4)

1 Like

Exacly what i needed, thank you Alex :wink:

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.