To calculate a period I use frappe.utils.add_month and frappe.utils.add_years
But it doesn’t return a period.

Example: start is Jan 20, 2020
If I add 1 month to start:

end = frappe.utils.add_months(start, 1)

this will return Feb 20, 2020
which for a period I expect the return to be Feb 19, 2020
so the next period also start on date 20 (Feb 20 - Mar 19)

Is there any function to do this period?
Or is there any way to deduct 1 day, something like frappe.utils.subtract_days(end,1)

Found solution:

end = frappe.utils.add_days(end, -1)

will return 1 day before.

1 Like

You can also try this, for more flexibility:

moment('2020-01-20').add(1, 'month').subtract(1, 'day').format()
// "2020-02-19"

It is of course best to use the framework but some cases are not possible.

I made this to get the previous week, month or year:

function previous(time, n=1) {
    const last_time = moment().subtract(n, time);
    return {
        start: last_time.startOf(time).format(),
        end: last_time.endOf(time).format(),

// {start: '2020-11-01', end: '2020-11-20'}
1 Like

Thanks @rmeyer,
Does it work in python?

Ah, no, that’s JS.

Thanks anyway.
Because of your moment I found a library for python moment :slight_smile:
But I stick to my code because it doesn’t have to install another library.