Skip to content

Instantly share code, notes, and snippets.

@smks
Created August 19, 2018 19:53
Show Gist options
  • Save smks/d64d28ce35e90474b6e852b697dcbf80 to your computer and use it in GitHub Desktop.
Save smks/d64d28ce35e90474b6e852b697dcbf80 to your computer and use it in GitHub Desktop.
Demonstrates using date-fns to compare days differences
import differenceInDays from 'date-fns/difference_in_days'
// Last day of tax year: 5th April 2018
const lastDayOfTaxYear = new Date(2018, 4, 5, 0, 0);
// My birthday: 18th September 2018
const myBirthday = new Date(2018, 9, 18, 0, 0);
const daysDiff = differenceInDays(myBirthday, lastDayOfTaxYear);
const content = document.createElement('p');
content.innerHTML = `<p>There are ${daysDiff} days between
the last day of tax year and my birthday</p>`;
document.body.appendChild(content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment