javascript - MomentJS: how to get last month date (not start of the month)? -
i'm using momentjs handle dates in project. need last month date starting current date.
i mean if today 6th april, when click on button should period between 7th march , 6th april. same should happen if, example, today 15th march: in case should period between 16th february , 15th march.
i read momentjs documentation , found these methods:
moment().subtract(1,'months'); moment().subtract(30, 'days'); as can see can't suit needs.
any idea?
you need add 1 day onto result if you're wanting day after day 1 month ago:
moment().subtract(1, 'month').add(1, 'day'); console.log("today:", moment().format("do mmmm")); console.log("month ago:", moment().subtract(1, 'month').add(1, 'day').format("do mmmm")); <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
Comments
Post a Comment