I have 3 people's birthdays:
Steve -> May 3
Mark -> October 20
Robbin -> December 5
How to loop through the remaining days of the year and find which person still has a birthday coming (IN THIS CASE output MARK AND ROBBIN)?
I've been able to get the remaing days of the year, but I'm not sure how to loop through the remaing days of the year and output those people's names (the ones that will have bithdays in the next months). This is what I have done so far:
I created a funtion to get the remaming days:
function remainingDays(date1, date2) {
// The number of milliseconds in one day
var ONE_DAY = 1000 * 60 * 60 * 24
var date1_ms = date1.getTime()
var date2_ms = date2.getTime()
var difference_ms = Math.abs(date1_ms - date2_ms)
// Convert back to days and return
return Math.round(difference_ms/ONE_DAY)
}
As you can see the function returns the number of days left. And here's the values:
var current_date = new Date()
// Store the date of the next New Year's Day
var new_years_date = new Date()
new_years_date.setYear(new_years_date.getFullYear() + 1)
new_years_date.setMonth(0)
new_years_date.setDate(1)
// Call the remainingDays function
var days_left = remainingDays(current_date, new_years_date);
if (days_left > 1) {
document.write(days_left + " days left this year")
} else {
document.write(days_left + " day left this year")
}
Please help me....Thank you in advanced!!