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(period, n=1) {
    const last_time = moment().subtract(n, period);
    return {
        from_date: last_time.startOf(period).format(),
        to_date: last_time.endOf(period).format(),

// {from_date: '2020-11-01', to_date: '2020-11-20'}

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.