Say I have an array of births
var bdates = ['1956-12-03', '1990-03-09',...]
I will put each through a function that will return those dates that have a birthday within 7 days from today (or now?). What I have at the moment:
var bdays = _.map(bdates, function(date) { var birthDate = new Date(date); var current = new Date(); var diff = current - birthDate;
The value 0.01995183087435 was determined from the number of milliseconds for 51 weeks and the division by milliseconds for 52 weeks, then one minus this ratio should be the variable "sevenDayDiff".
My JSFIDDLE , unfortunately, is not entirely clear. There are a number of errors in this. My sevenDayDiff may be the wrong value. There is also a problem with a leap year, even if I divide by 365.25. I could just do it wrong.
This happens in the web application, so the administrator can send an email to those people who have a birthday within 7 days. Any hints or suggestions are welcome.
source share