Canvas Apps UDFs - udfCalculateDurationInMonths

Fractional Month Calculations Without the Guesswork - Canvas Apps UDF snippet just for you!

Fractional Month Calculations Without the Guesswork - Canvas Apps UDF snippet just for you! Problem: Canvas Apps gives you DateDiff in whole months only. As soon as your business logic requires partial months (for billing, proration, contracts, or SLAs), formulas quickly become inconsistent and ugly across your apps. That’s where a reusable UDF saves you. What it does: πŸ‘‰ Calculates duration between two dates in fractional months πŸ‘‰ Accounts for different month lengths (28–31 days) πŸ‘‰ Rounds the result to 2 decimal places πŸ‘‰ Works consistently across year and month boundaries Examples: πŸ“… 2026-02-01 β†’ 2026-02-08 (1 week from 28-day month) = 0.25 πŸ“Š πŸ“… 2026-03-01 β†’ 2026-02-08 (1 week from 31-day month) = 0.23 πŸ“Š πŸ“… 2026-02-01 β†’ 2026-02-15 (2 weeks from 28-day month) = 0.5 πŸ“Š πŸ“…2026-02-01 β†’ 2026-03-02 (full month and 1 day from 31-day month) = 1.03 πŸ“Š Why this belongs in a UDF: πŸ‘‰ Accuracy: no β€œaverage month = 30 days” shortcuts πŸ‘‰ Reusability: one function for pricing, reporting, and validation πŸ‘‰ Readability: replace a multi-line formula with a single function call πŸ‘‰ Maintainability: adjust logic once, fix it everywhere Typical use cases: βœ”οΈ Subscription proration βœ”οΈ Contract duration calculations βœ”οΈ Financial or SLA reporting βœ”οΈ Any scenario where partial months actually matter As with other non-behavioural logic, this function fits perfectly into App.Formulas for Canvas Apps. Would you like to use it in your app? πŸ‘‡ Leave a reaction and use the link from the comments section! πŸ‘‡ ___ πŸ‘‰ Get snippet code: https://github.com/jan-chlebek/Power-Platform-Snippets/blob/main/udf-canvas-apps/source/udfCalculateDurationInMonths.yaml
Browse articles