What I am saying is that @gcusello's solution is the most generic because day, hour, minute can be algorithmically determined with no ambiguity. These are time units, whereas year and month are cale...
See more...
What I am saying is that @gcusello's solution is the most generic because day, hour, minute can be algorithmically determined with no ambiguity. These are time units, whereas year and month are calendar concepts. You cannot have month as duration because there is no meaningful definition of a month. (Week, on the other hand, can be calculated.) Using year is not very accurate. Yes, you can use 365.25 but that is still an approximation. If you insist on using year (but forego month), you can continue to use your formula, or this simplified one | eval duration=strptime(till,"%m/%d/%Y %I:%M %p")-strptime(from,"%m/%d/%Y %I:%M %p")
| eval years = round(duration / 86400 / 365.25)
| eval duration = years . " year(s) " . tostring(duration - years * 365.25 * 86400, "duration") The only way to define a "month" with time interval (duration) is if you choose a reference calendar. For example, use the Unix epoch zero calendar, namely 1970. | eval duration=strptime(till,"%m/%d/%Y %I:%M %p")-strptime(from,"%m/%d/%Y %I:%M %p")
| eval years = tonumber(strftime(duration, "%Y")) - 1970
| eval months = tonumber(strftime(duration, "%m")) - 1
| eval ymdt = years . " year(s) " . months . " month(s) " . strftime(duration, "%d") . " day(s) " . strftime(duration, "%T") Of course, you can also change reference calendar to a different year. But honestly I cannot see any useful application of this format. Here is an emulation: | makeresults format=csv data="from, till
11/28/2023 03:38 PM, 11/28/2024 04:08 PM"
``` data emulation above ``` It will give the following duration from months till years ymdt 31624200.000000 11/28/2023 03:38 PM 0 11/28/2024 04:08 PM 1 1 year(s) 0 month(s) 01 day(s) 16:30:00