Last active
April 11, 2017 20:16
-
-
Save JoseGonzalez321/81fe214ce6d1623173416e27ed1549d6 to your computer and use it in GitHub Desktop.
JavaScript: Comparing two dates with month and year only. JS Bin// source http://jsbin.com/lowugaj
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var selectedMonth = "1"; | |
var selectedYear = "2013"; | |
var selectedDate = new Date(selectedYear, selectedMonth); | |
var currentMonth = new Date().getMonth() + 1; | |
var currentYear = new Date().getFullYear(); | |
var currentDate = new Date(currentYear, currentMonth); | |
if (selectedDate.getTime() >= currentDate.getTime()) { | |
alert('OK!'); | |
} else { | |
alert('Failure. Date cannot be in past'); | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var selectedMonth = "1"; | |
var selectedYear = "2013"; | |
var selectedDate = new Date(selectedYear, selectedMonth); | |
var currentMonth = new Date().getMonth() + 1; | |
var currentYear = new Date().getFullYear(); | |
var currentDate = new Date(currentYear, currentMonth); | |
if (selectedDate.getTime() >= currentDate.getTime()) { | |
alert('OK!'); | |
} else { | |
alert('Failure. Date cannot be in past'); | |
} | |
</script></body> | |
</html> |
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
var selectedMonth = "1"; | |
var selectedYear = "2013"; | |
var selectedDate = new Date(selectedYear, selectedMonth); | |
var currentMonth = new Date().getMonth() + 1; | |
var currentYear = new Date().getFullYear(); | |
var currentDate = new Date(currentYear, currentMonth); | |
if (selectedDate.getTime() >= currentDate.getTime()) { | |
alert('OK!'); | |
} else { | |
alert('Failure. Date cannot be in past'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment