Skip to content

Instantly share code, notes, and snippets.

@aldraco
Created February 16, 2015 15:29
Show Gist options
  • Save aldraco/e76c8f089485ddc9b0f7 to your computer and use it in GitHub Desktop.
Save aldraco/e76c8f089485ddc9b0f7 to your computer and use it in GitHub Desktop.
Reddit /dailyprogrammer challenge from Feb 09, 2015.
module.exports = function(input) {
//take input string and parse to a date object.
var targetDate = Date.parse(input);
//figure out the current date, in a date object
var todaysDate = Date.now();
//find the difference between the two dates
var difference = targetDate - todaysDate;
//convert the difference to days.
/* Round up to include today as a "day," i.e. it's
one day until tomorrow, even though it's represented
as a few hours. */
difference = Math.ceil(difference / 86400000);
todaysDate = todaysDate.toString();
return difference + " days from 2015 2 16 to "+input;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment