This is a package module javascript for calculate the distance between two points.
Use npm, make sure your npm is up to date.
npm install simple-date-calculator
(date, date, details) type parameter
import calculating_date from "simple-date-calculator";
const distance = calculating_date.calculateDate(startDate, endDate, true);
- index.html
<!-- index.html -->
<form>
<label>Start Date</label>
<input type="date" name="startDate" />
<label>End Date</label>
<input type="date" name="endDate" />
</form>
<script src="script.js"></script>
- script.js
const calculateDate = require("simple-date-calculator");
const startDate = document.querySelector("input[name=startDate]");
const endDate = document.querySelector("input[name=endDate]");
const distance = calculateDate.calculateDate(startDate.value, endDate.value);
console.log(distance);
(test.mjs)
import { calculateDate } from "simple-date-calculator";
// day different = [{ dayDiff: 2 Day }]
console.log(calculateDate("2022-04-15", "2022-04-17"));
// day, month different = [{ dayDiff: 3 Day, monthDiff: 2 Month }]
console.log(calculateDate("2022-04-15", "2022-06-17"));
// day, month, year different = [{ dayDiff: 8 Day, monthDiff: 2 Month, yearDiff: 1 Year }]
console.log(calculateDate("2022-04-15", "2023-06-17"));
(test.js)
const calculating_date = require("simple-date-calculator");
// day different = [{ dayDiff: 2 Day }]
console.log(calculateDate("2022-04-15", "2022-04-17"));
// day, month different = [{ dayDiff: 3 Day, monthDiff: 2 Month }]
console.log(calculateDate("2022-04-15", "2022-06-17"));
// day, month, year different = [{ dayDiff: 8 Day, monthDiff: 2 Month, yearDiff: 1 Year }]
console.log(calculateDate("2022-04-15", "2023-06-17"));