I have a function that gets the birthdate( only day and month) and compares if its between 2 dates newsigndate is undefined.why? and also AriesFrom and AriesTo.
what to do?
I want to compare the birth date according to day and month for example is 21/3>21/2
yes
return Aries
thanks
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
function yourSign() {
var signDate = $("input[name='birthDate']").val();
tempsignDate = signDate.split("-").join("/");
newsignDate = tempsignDate.substring(5, 10);
var AriesDateFrom = "21/03";
var AriesDateTo = "20/04";
var Ad1 = AriesDateFrom.split("/");
var Ad2 = AriesDateTo.split("/");
var s = newsignDate.split("/");
//var date = new Date().getDay() + "/" + new Date().getMonth() + 1
var AriesFrom = new Date(Ad1[1], Ad2[2]);
newsignDate = new Date(s[1], s[2]);
if (newsignDate == "") {
alert("enter birthday");
} else if (newsignDate >= AriesFrom && newsignDate < AriesTo) {
$("#output").val("Aries");
}
}
</script>
Here's a tip that might help think about this a little differently:
Instead of thinking about a bunch of date ranges, just think about a list of the last dates of the range. Now you can go through that list and find the first one that is greater than or equal your date. (it will be easier to compare dates is they are in
MMDDformat).One way to do this in practice is to use the
find()function of an array tofindthe first date greater than your given date:Now you just need to transform your input into
MMDDformat and extract the sign from the array returned byfind()