1 year ago
#332821
Sim
Compare input date with epoch time jQuery/JavaScript
I have snippet I wrote up, though I am a beginner at jQuery & JavaScript so I have no idea what is wrong with the piece of code. I did substantial Googling & StackOverflow searching, to no avail.
I am attempting to retrieve the date from a date field that a user has input (field is: #input_1_12), and compare it with other date times that have been passed as epoch times. When I run the form, the field I want to populate with the code (id: #input_1_111) stays empty.
p.s. I am implementing this in a WordPress site, so I used "jQuery" instead of "$" in the if statement to make sure there's no compatibility issues. Any help would be greatly appreciated!
var saveDate = new Date($('#input_1_12').val());
var firstQdate = new Date(1554076800);
var secondQdate = new Date(1561939200);
var q1of19 = $('#input_1_22').val();
var q1of20 = $('#input_1_26').val();
var q2of19 = $('#input_1_23').val();
var result;
if ( saveDate < firstQdate ) {
result = q1of19 / q1of20 ;
jQuery('#input_1_111').val(result).trigger('change');
}
else if ((saveDate > firstQdate) && (saveDate < secondQdate)) {
result = q2of19 / q1of20 ;
jQuery('#input_1_111').val(result).trigger('change');
}
javascript
jquery
wordpress
date
epoch
0 Answers
Your Answer