I have problem with the code below. I'm trying to return all votes between two dates, but for some reason it doesn't work well.
FirstShiftStart date -> 2022-12-21 8:0:0
FirstShiftEnd date -> 2022-12-21 14:0:0
let current_datetime = new Date();
var firstShiftStart = current_datetime.getFullYear() + "-" + (current_datetime.getMonth() + 1) + "-" + current_datetime.getDate() + " " + 08 + ":" + 00 + ":" + 00;
var firstShiftEnd = current_datetime.getFullYear() + "-" + (current_datetime.getMonth() + 1) + "-" + current_datetime.getDate() + " " + 14 + ":" + 00 + ":" + 00;;
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = yyyy + '-' + mm + '-' + dd;
votesforDay is returning only today's records(all data is ok).
However, the last line it's returning empty array.
var votesforDay = dataAllJson.filter(x => x.Created >= today);
int likesFirstShift = votesforDay.filter(x => x.Created >= firstShiftStart && x.Created <= firstShiftEnd && x.Choice == "Like").length;
int likesFirstShift = votesforDay.filter(x => x.Created >= firstShiftStart && x.Created <= firstShiftEnd && x.Choice == "Like").length;
Choice: "Like"
Created: "2022-12-21 07:50:04"
Id: 12123
Via Active questions tagged javascript - Stack Overflow https://ift.tt/YEZ2VX8
Comments
Post a Comment