I found the issue now. The values being compared is string vs. dates. So I converted dates back to string for comparison. That did the trick. Thanks.
myPlot.on('plotly_relayout', function () {
var xRange = myPlot.layout.xaxis.range;
var ptsInside = [];
var N = trace1.x.length;
var count = 0;
for (var i = 0; i < N; i++) {
var xi = trace1.x[i];
d1 = (new Date(xRange[0]));
d2 = (new Date(xRange[1]));
var ds1 = d1.getUTCFullYear() + "-" + pad(d1.getUTCMonth() + 1) + "-" + pad(d1.getUTCDate());
var ds2 = d2.getUTCFullYear() + "-" + pad(d2.getUTCMonth() + 1) + "-" + pad(d2.getUTCDate());
if (xi >= ds1 && xi <= ds2) {
console.log('pushed: ' + xi);
count++;
ptsInside.push(i);
}
}
});