This is how I achieved it:
<script type="text/javascript">
// Get this monday
var dif, d = new Date();
dif = (d.getDay() + 6) % 7;
d = new Date(d.getTime() - dif * 24*60*60*1000);
d.setHours(0,0,0);
var thisMondayUnixtimestamp = Math.round((d.getTime() / 1000));
console.log('thisMondayUnixtimestamp', thisMondayUnixtimestamp);
// Get last monday
var beforeOneWeek = new Date(new Date().getTime() - 60 * 60 * 24 * 7 * 1000)
, day = beforeOneWeek.getDay()
, diffToMonday = beforeOneWeek.getDate() - day + (day === 0 ? -6 : 1)
, lastMonday = new Date(beforeOneWeek.setDate(diffToMonday));
lastMonday.setHours(0,0,0);
var lastMondayUnixtimestamp = Math.round(lastMonday.getTime() / 1000);
console.log('lastMondayUnixtimestamp = ', lastMondayUnixtimestamp);
</script>
This works. Today is 24th of Jan 2016 and the timestamp values parsed returns the following:
last Monday: string '11/01/2016 01:00:00' (length=19) this Monday: string '18/01/2016 01:00:00' (length=19)
Although this works, I am uncertain if it's correct and reliable as I have put the above together from snippets found via googling.
Is there a more elegant way to do this?