Hi, I have two scripts. They count upcoming birthdays.
The first script checks in a list of dates if there is a match in the next 7 days:
The second script calculates how many years are completed for today:HTML Code:<html> <head> <script type="text/javascript"> var arrBday = [ ['24 май', '05/24', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'], ['Másvalaki Kitti', '9/6', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'], ['Mégvalaki Kálmán', '9/1', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'], ['John Doe', '05/6', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'], ['John Doe4', '05/25', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'], ['John Doe6', '5/24', 'https://lh3.googleusercontent.com/-_twxuIarFO0/XsouOYLkGVI/AAAAAAAAaP0/6wSA5GCyGMco4S8tTOs6V3WI5eO0yw9QwCLcBGAsYHQ/w30/5f76aaa.jpg'] ]; function getBdaysThisWeek(){ var arrMonth = new Array("Януари", "Февруари", "Март", "Април", "Май", "Юни", "Юли", "Август", "Септември", "Октомври", "Номеври", "Декември"); var bday, idx; var bdayList = new Array(); var today = new Date(); for (var i=0;i<arrBday.length;i++){ var bday = new Date(arrBday[i][1] + '/' + today.getFullYear()); if (isNaN(bday)) continue; if ( isBdayInRange(bday, 7) ){ idx = bdayList.length; bdayList[idx] = new Object(); bdayList[idx].name = arrBday[i][0]; bdayList[idx].bday = bday; bdayList[idx].month = arrMonth[bday.getMonth()]; bdayList[idx].pic = arrBday[i][2]; } } if (bdayList.length > 0){ //sort asc by birthdate bdayList.sort( function(a, b){ if (a.bday < b.bday) return -1 if (a.bday > b.bday) return 1; return 0; } ); } return bdayList; } function isBdayInRange(bday, interval){ //credit for this function goes to: //-Rob (@slingfive) Eberhardt, Slingshot Solutions //http://slingfive.com/pages/code/jsDate/jsDate.html var today = new Date(); today.setHours(0,0,0,0); if (bday < today) bday.setFullYear(bday.getFullYear() + 1); var iDiffMS = bday.valueOf() - today.valueOf(); nDays = parseInt(iDiffMS / 1000 / 60 / 60 / 24); if(parseInt(nDays) <= parseInt(interval)) return true; else return false; } function displayBdayList(){ var date = new Date().getDate(); var bdayList = getBdaysThisWeek(); var len = bdayList.length; var s = "<h1>Предстоящи събития:</h1>"; if (len>0){ s += '<ul>'; for (var i=0; i<len; i++){ //be mindful of the string-line continuation character (\) at the end of the first line s += '<li' + ((date == bdayList[i].bday.getDate())?' class="bdayToday"':'')+ '>\ <img src="' + bdayList[i].pic + '"> ' + '<strong>' + bdayList[i].name + '</strong> – ' + bdayList[i].month + ' ' + bdayList[i].bday.getDate() + '</li>'; } s += '</ul>'; } else{ s += "<h5>Няма събития.</h5>"; } document.write(s); } </script> <style type="text/css"> body { font:14px Verdana; } .bdayToday { color: red; } </style> </head> <body> <script type="text/javascript">displayBdayList();</script> </body> </html>
Please help me to publish the list of upcoming events, adding to them how old they are.HTML Code:<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript"> var arrBday = [ ['Adrian','5/24/1973'], ['Peter','5/24/1977'], ['John','12/2/1999'], ]; function displayBdayList(today) { var bday,strList=''; for(var i = 0; i < arrBday.length; i++) { bday = new Date(arrBday[i][1]); if(!isNaN(bday) && bday.getMonth()==today.getMonth() && bday.getDate()==today.getDate()) strList += '' + arrBday[i][0] + " (" + (today.getFullYear() - bday.getFullYear()) + " години)<br>"; } if(strList == '') strList = 'Няма отбелязано събитие' document.getElementById("bday").innerHTML = "<h4>НА ДНЕШНАТА ДАТА:</h4>"+strList; } </script> </head> <body> <div id="bday"></div> <script type="text/javascript"> window.onload=function() { displayBdayList(new Date()); } </script> </body> </html>



Reply With Quote
Bookmarks