after-before-date
v1.0.1
Published
JavaScript library to get after/before or add/substract date and time.
Downloads
3
Maintainers
Readme
after-before-date
JavaScript library to get after/before or add/substract date and time.
Node.js (Install)
Requirements:
- Node.js
- npm (Node.js package manager)
npm i after-before-date
Or
npm i after-before-date --save
Usage
Modular include:
const tempVar = require("after-before-date");
Use in method
use afterDate
to get date after a given date
use beforeDate
to get date before a given date
let next = tempVar.afterDate(payload, mydate);//for getting date after the given date (mydate here)
let prev = tempVar.beforeDate(payload, mydate);//for getting date before the given date (mydate here)
Input params
- payload => an object with your input parrams
- mydate => any date object or date string with any format, Default is current datetime
Payload Params
{
y: 'years value',
m: 'months value',
w: 'weeks value',
d: 'days value',
h: 'hours value',
M: 'minutes value',
s: 'seconds value',,
ms: 'milliseconds value',
}
/**
Note : Please distinguish between m(lowercase for Month) and M(uppercase for Minute)
*/
SOME EXAMPLES
1. If you want to get a date after 30 years 6 months 7 days from today
let payload = {
y: 30,
m: 6,
d: 7,
}
let afterYears = tempVar.dateAfter(payload);
console.log(afterYears);// 2050-02-22T14:56:50.000Z
2. If you want to get a date after 30 years 6 months 7 days from a definite date like 2019-07-07
let payload = {
y: 30,
m: 6,
d: 7,
}
let afterYears = tempVar.dateAfter(payload, '2019-07-07');
console.log(afterYears);//2050-01-14T05:30:00.000Z
3. For getting date before 40 weeks from a definite date like 2019-07-07
let payload = {
w: 40,
}
let beforeWeeks = tempVar.dateBefore(payload, '2019-07-07');
console.log(beforeWeeks);//2018-09-30T05:30:00.000Z
4. For getting date(or datetime) after 27 hours 45 minutes 30 seconds from a datetime like 2019-07-07 08:00:00
let payload = {
h: 27,
M: 45,
s: 30,
}
let afterHours = tempVar.dateAfter(payload, '2019-07-07 08:00:00');
console.log(afterHours);//2019-07-08T11:45:30.000Z
5. Want to get next date or prev date
let nextDate = tempVar.dateAfter();
console.log(nextDate);
let prevDate = tempVar.dateBefore();
console.log(prevDate);