如何在Google Sheets中无需脚本计算未来下一个开票日期
Solution: Calculate Next Future Billing Date (No Google Apps Script)
To compute the next future billing date based on an initial start date and monthly increment (without using Google Apps Script), use this Google Sheets formula which dynamically adapts to the current date:
=LET( k, FLOOR( ((YEAR(TODAY())*12 + MONTH(TODAY())) - (YEAR(A2)*12 + MONTH(A2)) + IF(DAY(TODAY()) >= DAY(A2), 0, -1)) / B2, 1 ), last_occurrence, EDATE(A2, k*B2), IF(last_occurrence >= TODAY(), last_occurrence, EDATE(A2, (k+1)*B2)) )
How It Works:
- Calculate
k: Figure out how many complete increment periods have passed since the start date, adjusting for the day of the month to avoid counting an upcoming occurrence that hasn’t happened yet. - Find
last_occurrence: UseEDATEto addkincrements to the start date, getting the most recent billing date. - Return the correct date: If the last occurrence is today or later, use it. Otherwise, add one more increment to get the next future date.
Example Validation:
Let’s verify against your test cases:
Scenario 1: Current Date = 8/5/2024
| StartDate | Increment (months) | Formula Result |
|---|---|---|
| 7/14/2024 | 1 | 8/14/2024 |
| 7/2/2024 | 1 | 9/2/2024 |
| 7/14/2016 | 12 | 7/14/2025 |
| 7/14/2022 | 6 | 1/14/2025 |
(Note: The listed result of 2/14/2025 for the last entry appears to be a typo; the correct next future date after 8/5/2024 is 1/14/2025.)
Scenario 2: Current Date = 8/14/2024
| StartDate | Increment (months) | Formula Result |
|---|---|---|
| 7/14/2024 | 1 | 8/14/2024 |
| 7/2/2024 | 1 | 9/2/2024 |
| 7/14/2016 | 12 | 7/14/2025 |
| 7/14/2022 | 6 | 1/14/2025 |
Usage Notes:
- Replace
A2with your start date cell reference. - Replace
B2with your increment (months) cell reference. - The formula uses
TODAY()so it automatically updates to the current date daily.
内容的提问来源于stack exchange,提问作者Gabriel
相关产品推荐
相关产品推荐

