Created
August 2, 2017 11:44
-
-
Save alokstha1/86852f61212dcff26ca89822ec72b6e0 to your computer and use it in GitHub Desktop.
Compare two dates in jquery
This file contains hidden or 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 myStringToDate(str) { | |
var arr = str.split("-"); // split string at slashes to make an array | |
var yyyy = arr[2] - 0; // subtraction converts a string to a number | |
var jsmm = arr[1] - 1; // subtract 1 because stupid JavaScript month numbering | |
var dd = arr[0] - 0; // subtraction converts a string to a number | |
return new Date(yyyy, jsmm, dd); // this gets you your date | |
} | |
var from_date = myStringToDate(jQuery('#from-date').val()); | |
var to_date = myStringToDate(jQuery('#to-date').val()); | |
if ( to_date.getTime() > from_date.getTime() ) { | |
//Do your operations | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment