I need to find the difference in hours between a certain date and Sunday at 00:01 on the same week.
For example, if the given date is today (Saturday, June 18 2016), I need to find the difference between it and Sunday, June 12 2016 at 00:01.
I basically need to go back from the given date to its last Sunday and find the difference.
This is what I have
var date = new Date($scope.newGame.date);
var time = $scope.newGame.time.replace(':', ',');
date.setHours(parseInt(time));
date = date.getTime();
console.log(date); // Logs 1466272800000
var t = new Date().getDate() + (8 - new Date().getDay() - 1) - 7 ;
var d = new Date();
d.setHours(0,0,0,1);
d.setDate(t);
var lastSunday = new Date(d).getTime();
var hourDiff = 1466272800000 - lastSunday;
var hoursDifference = Math.floor(hourDiff/1000/60/60);
console.log(hoursDifference); // Logs 164
This works well. Now I just need to find the difference if the given date is not on this week by going back to its last Sunday