Skip to content

Instantly share code, notes, and snippets.

@zeuxisoo
Last active September 26, 2015 07:17
Show Gist options
  • Save zeuxisoo/1059749 to your computer and use it in GitHub Desktop.
Save zeuxisoo/1059749 to your computer and use it in GitHub Desktop.
javascript calcate between days
function betweenDays(first_date, second_date, separator) {
var separator = separator || "-",
first_date_parts = first_date.split(separator),
second_date_parts = second_date.split(separator),
first_date_object = new Date(first_date_parts[0], first_date_parts[1], first_date_parts[2]),
second_date_object = new Date(second_date_parts[0], second_date_parts[1], second_date_parts[2]),
between_time = Math.abs(first_date_object.getTime() - second_date_object.getTime());
return between_time/(1000*60*60*24);
}
betweenDays("2011/06/01", "2011/06/02", "/");
betweenDays("2011-06-01", "2011-06-02");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment