I have several dates in a list. I want to organise these dates into weeks.
For example if I have each day from 2015-10-07 to 2015-10-14 then these will be ordered into a ul list. Any days that do not form a consecutive 7 days will be put into their own list. So if I also have 2015-10-18 that will be wrapped into it’s own separate ul list unless there is a day to follow (2015-10-19) in which case that will be wrapped along with the 2015-10-18 date until 7 consecutive days are available. After 7 consecutive days have been wrapped, a new ul list will begin.
This is an example of a HTML list that is generated on the page:
I could do this with both, however it would be preferred to do it with Javascript.
I currently have a calendar (fullcalendar by Adam Shaw) loaded onto a page, once a date on the calendar is checked then that is put into an array (selectedDays), I then sort the array and output the dates using the following:
function sortDates(a, b)
{
return new Date(b).getTime() - new Date(a).getTime();
}
var sorted = selectedDays.sort(sortDates);
var vPool="";
jQuery.each(sorted, function(i, val) {
vPool += '<li id="sale-'+ val +'" class="sale-listing"><div class="sale-view"><p>' + val +'</p></div></li>';
});
//We add vPool HTML content to #date-list
$('#date-list').html(vPool);
Hi megazoid, I’m having a little difficulty with the code you provided. Everything works fine until the 25-26th October 15, then it puts these two dates on new rows even though they’re consecutive. I’m presuming this is due to the clocks go back 1 hour on the 25th. Here is what is happening - http://jsfiddle.net/g3nabqte/3/ have you got any idea how to stop it doing this?