I'll admit I'm a bit of a JS novice, and coming from a PHP background, my idea of scope is clearly different to Javascript's.
// There's a date set, so begin processing
var original_date = new Date($('input#tour_encoded_dates').val());
var date_search_string = '';
var day_limit = 14;
var timestamp = '';
// Go forwards day_limit days
for(var i = 0; i < day_limit; i++) {
timestamp = strtotime('+'+i+' days', original_date);
calculated_date = new Date(timestamp).format('Y-m-d');
date_search_string += calculated_date + ' ';
}
console.log(date_search_string);
The output from console.log() is:
2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10 2013-10-10
I would have expected each iteration to increase the date by one day, but they remain the same.
For reference, if I change the final line of the loop to date_search_string += timestamp + ' '; the output is as follows:
1381363200000 1381363286400 1381363372800 1381363459200 1381363545600 1381363632000 1381363718400 1381363804800 1381363891200 1381363977600 1381364064000 1381364150400 1381364236800 1381364323200
So the issue is clearly with the calculated_date variable - right?
Can someone explain the proper way to do this? Thanks.
day_limit? is that a number? if it's an array you need to useday_limit.lengthto get the number of stuff in it. isoriginal_dateinside ofday_limit?