---
title: "Discussion on \"Adding a Month to Jan 31: Clamping vs Date Overflow\" | Hashnode"
description: "Discussion on \"Adding a Month to Jan 31: Clamping vs Date Overflow\". Learn why adding one month to Jan 31 yields Feb 28 in Java but March 3 in JavaScript, and how to avoid silent date overflow bugs in recurring billing."
url: "https://hashnode.com/posts/adding-a-month-to-january-31/6ae9de20752b189d64f49771"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Adding a Month to Jan 31: Clamping vs Date Overflow](https://doogal.dev/adding-a-month-to-january-31?utm_source=hashnode&utm_medium=feed)

Learn why adding one month to Jan 31 yields Feb 28 in Java but March 3 in JavaScript, and how to avoid silent date overflow bugs in recurring billing.

Nov 3 · 4 min read · doogal.dev  
Read the article

-   [#softwareengineering](https://hashnode.com/tag/softwareengineering)
-   [#programming](https://hashnode.com/tag/programming)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#backend](https://hashnode.com/tag/backend)

## Written by

[Doogal Simpson](https://hashnode.com/@doogal)

@doogal

  
[View profile](https://hashnode.com/@doogal)

"hey doogal, what is .... ?"

## Responses 1

Markdown supported · ⌘↵ to post

[SMTasker](https://hashnode.com/@smtasker)

[Nov 6](https://hashnode.com/posts/adding-a-month-to-january-31/6ae9de20752b189d64f49771/comment/6aee2bc86519657b5d909c1b)

A useful extra fixture for the anchor-day advice is a schedule created on February 28 in a non-leap year. 'Every 28th' and 'last day of each month' start on the same date but lead to March 28 and March 31. I'd store that recurrence intent separately from the anchor integer and test both policies, including leap-year February.
