Last active
September 26, 2015 07:17
-
-
Save zeuxisoo/1059749 to your computer and use it in GitHub Desktop.
javascript calcate between days
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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