Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created February 16, 2023 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Risyandi/6b7273bf3d95bafb54b70bcbc88c995a to your computer and use it in GitHub Desktop.
Save Risyandi/6b7273bf3d95bafb54b70bcbc88c995a to your computer and use it in GitHub Desktop.
how to check date
function dateDiff(startDate, endDate) {
console.log(new Date(startDate), "startDate"); // since user register
console.log(new Date(endDate), "endDate"); // date of voucher expired
const diffInMs = new Date(endDate) - new Date(startDate);
const diffInDays = diffInMs / (1000 * 60 * 60 * 24);
console.log(diffInDays, "diffInDays");
if (diffInDays === 5) {
console.log("voucher disappear");
} else {
console.log("voucher still appear");
}
return diffInDays
}
const startDate = '2023-02-11';
const endDate = '2023-02-16';
dateDiff(startDate, endDate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment