Subtract Dates from each other

Hi, and welcome to the forum! :slight_smile:

You can do this using the "X" format option for the {time} command. It converts the time/date to a timestamp which is the number of seconds since 1970 (this is a standard unit of time for computer systems). You can then use that to calculate the time between two dates.

For example:

Budget: ${formtext: name=budget; default=10000}
Start Date: {formtext: name=start; default=2020-01-01} (YYYY-MM-DD format)
End Date: {formtext: name=end; default=2020-01-31}

{days=({time: X; at={=end}} - {time: X; at={=start}}) / 24 / 60 / 60} (calculate difference in seconds and then convert to days)

Per day rate {=budget / days; format=$,.2f}

As an aside, we're planning on launching a date selector in the coming months that will make entering a date simpler. You can take an early look at it here:

3 Likes