{"uid":"cap_Bgp81bwyHEwrldmheKLCO","slug":"date-math-subscription-contract-date-math-ae53c855","name":"Date Math: Subscription & Contract Date Math","description":"Date Math: Subscription and contract date math: current billing period, next renewal, upcoming renewals, cancel-by date for a notice period, free-trial start, and day-based proration of a price. Month-end anchors stay at month end (Jan 31, Feb 28, Mar 31). Use for SaaS billing, renewals, cancellation deadlines and refunds.","url":"https://date-math.datemath.workers.dev/v1/subscription?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"as_of":{"type":"string","example":"2026-11-07","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"count":{"type":"integer","default":3,"maximum":24,"minimum":1,"description":"Upcoming renewals to list"},"start":{"type":"string","example":"2026-11-07","pattern":"^\\d{4}-\\d{2}-\\d{2}$"},"amount":{"type":"number","minimum":0,"description":"Price of one billing period, for proration"},"interval":{"enum":["day","week","month","year"],"type":"string","default":"month"},"trial_days":{"type":"integer","maximum":730,"minimum":0,"description":"Free trial length; billing starts after it"},"notice_days":{"type":"integer","maximum":365,"minimum":0,"description":"Cancellation notice period before renewal"},"interval_count":{"type":"integer","default":1,"maximum":365,"minimum":1,"description":"e.g. 3 with month = quarterly"}}},"responseSchema":{"type":"json","example":{"note":"Renewals are measured from the first billing date, so month-end anchors stay at month end (Jan 31 -> Feb 28 -> Mar 31). Proration is by whole days as of the start of as_of.","as_of":"2026-03-10","start":"2026-01-31","status":"active","interval":"month","cancel_by":"2026-03-24","proration":{"used":9.68,"amount":30,"unused":20.32,"daily_rate":0.967742,"ratio_unused":0.677419},"next_renewal":"2026-03-31","billing_start":"2026-01-31","current_period":{"end":"2026-03-30","days":31,"start":"2026-02-28","number":2,"days_elapsed":10,"days_remaining":21},"interval_count":1,"cancel_by_passed":false,"upcoming_renewals":["2026-03-31"],"next_renewal_weekday":"Tuesday"}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.001","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_JJ0KVlJt5NdDDIygoGt0t","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.001","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Computes subscription billing periods, next renewal dates, cancel-by deadlines, free-trial starts, upcoming renewals, and day-based proration for a given subscription interval and start date.","exampleAgentPrompt":"My SaaS subscription started on January 31, 2026, bills monthly at $30, and I need a 7-day cancellation notice — as of March 10, 2026, what billing period am I in, when is my next renewal, what's my cancel-by deadline, and how much of the $30 is unused?","exampleUseCases":[{"title":"Cancel-by deadline for annual SaaS contract","prompt":"My annual software contract started on March 15, 2025, and requires 30 days' notice before renewal — as of today, March 10, 2026, what's the last date I can cancel before it auto-renews?"},{"title":"Proration refund on mid-cycle cancellation","prompt":"A customer on a $99/month plan that started February 28 wants to cancel today, April 10, 2026 — how many days have they used, what's the daily rate, and how much of the $99 is unused and potentially refundable?"},{"title":"Free trial billing start and upcoming renewals","prompt":"I'm starting a quarterly subscription at $150 per period on November 7, 2026, with a 14-day free trial — when does billing actually begin, and what are the next 4 renewal dates after that?"}],"resultDescription":"A JSON object containing: current billing period details (start, end, number, days elapsed, days remaining), next renewal date and weekday, a list of upcoming renewal dates, billing start date, cancel-by date and whether it has passed, subscription status, and a proration breakdown (daily rate, used amount, unused amount, unused ratio) — with month-end anchor behavior preserved across months.","failureModes":["Invalid date format (non-YYYY-MM-DD) returns a validation error","interval_count or count outside allowed min/max bounds returns a 422 error","trial_days or notice_days exceeding maximum values rejected","Missing required start date causes a 400 bad request","Payment of 0.001 USDC not provided triggers a 402 Payment Required response","as_of date before start date may produce unexpected period calculations"],"whenToPreferThis":"Use this endpoint when you need precise SaaS or contract billing calculations — especially month-end anchor preservation (Jan 31 → Feb 28 → Mar 31), cancel-by deadline computation with a notice period, free-trial offset billing starts, day-accurate proration of a dollar amount, or a projected list of upcoming renewal dates. Prefer this over generic date-addition endpoints when the domain is subscription lifecycle management and you need multiple related outputs in one call.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-11-21T12:36:32.114Z","isFirstParty":false,"canonicalSlug":"date-math-subscription-contract-date-math-ae53c855"}