Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

add-months and add-one-month functions (See related posts)

add-months: func [
    date [date!]
    count [integer!] "Number of months to add"
    /local res
] [
    res: make date! reduce [date/day date/month + count date/year]
    ; If date/day is greater than the last day in the calculated
    ; month, we'll be at count+1 months, so we walk backwards until
    ; we find the last day of the previous month.
    while [(res/month - date/month) > count] [res: res - 1]
    res
]

add-one-month: func [date [date!]] [add-months date 1]

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts