Actually, i am stuck in one problem that is about Date.
I want to subtract and plus the date in react native.
is there any solution about it.
I have used Moment.js but the error occurs in it so please help me.
Thank you in advance
check below working example of add and subtract day, month and date using moment:
For Day
let tomorrow = new Date();
tomorrow = moment(tomorrow).add(1, 'day').format('YYYY-MM-DD'); // for specific format
let today = moment(new Date()).format('YYYY-MM-DD');
let tomorrow = new Date();
tomorrow = moment(tomorrow).add(1, 'day').format('YYYY-MM-DD');
For Month
moment(currentMonth).add(1, 'month');
moment(currentMonth).subtract(1, 'month');
For Date
let now = "14/11/2016";
let then = "03/12/2017";
let diff = moment(now,"DD/MM/YYYY").diff(moment(then,"DD/MM/YYYY"));
let duration = moment.duration(diff);
let result = duration.format("hh:mm:ss");
Please refer detailed date difference: https://stackoverflow.com/a/18624295/6592263
EDIT (Not tested)
To get Month
let d = moment(new Date());
d.month(); // month number
d.format('ddd MMM DD YYYY');
TO get Year
let d = moment(new Date());
d.year() // year
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With