WelshFlyer 09-22-2003, 02:46 PM This script determins the current date, and if that date is someones birthday (from a list of birthdays, names and dates) It prints a customisable message.
(different message for eagh entry if you want!)
It's a very simple script but it works well. Put it between HTML tags to change the output text apperance.
Here is the script:
<script language="JavaScript">
var date=new Date()
var year=date.getYear()
if (year < 1000)
year+=1900
var day=date.getDay()
var month=date.getMonth()
var daym=date.getDate()
//Birthday List
if ((month = 9) && (date = 21)) document.write("somebody's birthday");
</script>
//to add more that one entry, just copy the first and paste it back into the script, changing the contents
Please tell me what you think of the script. It's free to use, but if you do use it please let me know.
WF.
glenngv 09-22-2003, 04:28 PM Well, how about this:
<script language="JavaScript">
var arrBday = [
['Bob','11/23/1973'],
['Peter','9/22/1977'],
['John','9/22/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='- NONE'
document.write("<h4>Today's Birtdays:</h4>"+strList)
}
displayBdayList(new Date());
</script>
WelshFlyer 09-22-2003, 07:25 PM Isuppose that my script could be used for anything - From birthdays to when payment is due for something like a subscription for some service for example.
Nice script Glenn, musch better than mine!
slight modification:
<script language="JavaScript">
var date=new Date()
var year=date.getYear()
if (year < 1000)
year+=1900
var day=date.getDay()
var month=date.getMonth()
var daym=date.getDate()
//Birthday List
if ((month = 9) && (date = 21)) window.alert("Please wish somebody a Happy Birthday");
</script>
nath192 08-04-2005, 09:04 AM hi there
i really like Glens birthday script and would like to use it. I just wandered if it is possible to display peoples birthdays falling in the next 2 weeks (14 days) instead of just on todays date.
and also i would like to to display the birthdays in a horizontal comma separated row instead of a vertical list, can anyone help with that please.
your help would be very much appreciated!
many thanks, nathan.
<script language="JavaScript">
var arrBday = [
['Bob','11/23/1973'],
['Peter','9/22/1977'],
['John','9/22/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='- NONE'
document.write("<h4>Today's Birtdays:</h4>"+strList)
}
displayBdayList(new Date());
</script>
glenngv 08-04-2005, 10:20 AM <html>
<head>
<title>Birthday List</title>
<script type="text/javascript">
Date.prototype.getDiff = function(date, interval){
if (typeof date == "string"){
date = new Date(date);
}
if (isNaN(date) || !(date instanceof Date)){
return NaN; //invalid date passed
}
if (typeof interval == "undefined") interval = "ms"; //msec (default)
var diff = this - date; //alert(this+' - '+date+" = "+diff)//diff in msec
switch(interval.toLowerCase()){
case "s": //sec
diff = diff/1000; break;
case "n": //min
diff = diff/(1000*60); break;
case "h": //hr
diff = diff/(1000*60*60); break;
case "d": //day
diff = diff/(1000*60*60*24); break;
case "m": //month
diff = diff/(1000*60*60*24*30); break;
case "y": //year
diff = diff/(1000*60*60*24*365); break;
default:
; //msec
}
return Math.floor(diff);
}
var arrBday = [
['Bob','7/23/1973'],
['Glenn','8/4/1989'],
['Nathan','8/11/1999'],
['Peter','8/18/1977'],
['John','8/19/1999']
];
function getBdayList(numDays){
var bday,temp,idx,diff;
var today = new Date();
var bdayList = new Array();
for (var i=0;i<arrBday.length;i++){
bday = new Date(arrBday[i][1]);
if (isNaN(bday)) continue;
temp = new Date(today.getFullYear(), bday.getMonth(), bday.getDate(), 23, 59, 59, 999);
diff = temp.getDiff(today, "d");
if (diff >= 0 && diff <= numDays){
idx = bdayList.length;
bdayList[idx] = new Object();
bdayList[idx].name = arrBday[i][0];
bdayList[idx].bday = arrBday[i][1];
bdayList[idx].age = today.getDiff(bday, "y");
if (diff > 0) bdayList[idx].age = bdayList[idx].age + 1;
}
}
return bdayList;
}
function displayBdayList(){
var bdayList = getBdayList(14);
var len = bdayList.length;
var s = "";
if (len>0){
for (var i=0; i<len; i++){
if (s != ""){
s += ", " + bdayList[i].name + " - " + bdayList[i].bday + " (" + bdayList[i].age + ")";
}
else{
s = bdayList[i].name + " - " + bdayList[i].bday + " (" + bdayList[i].age + ")";
}
}
}
else{
s = "No birthdays.";
}
document.write(s);
}
</script>
</head>
<body>
<h1>Birthday Celebrants</h1>
<script type="text/javascript">
displayBdayList();
</script>
</body>
</html>
nath192 08-04-2005, 11:38 AM many thanks Glen.
its looking great. i prefererd it without displaying the actual birthdate and managed to remove that.
is it possible so that the name of a person has a hyperlink to it.
var arrBday = [
['Bob'<a href=http://www.bob.co.uk>,'8/11/1973'],
['Nathan<a href=http://www.nathy.co.uk>','08/06/1983'],
['Glen<a href=http://www.glen.co.uk>','8/11/1999'],
]
when i try and do this it doesnt hyperlink the names properly. it would be great if it could hyperlink the name and age eg: Nathan - (6) (http://)
and one final query, would it be possible to have a person with a birthday actually today displayed above the list of persons within the next 14 days. if thats too complicated no problem.
eg
Birthday Celebrants
Today Michael (15)
Within next 14 days Glenn - 8/4/1989 (16), Nathan - 8/11/1999 (6), Peter - 8/18/1977 (28)
many thanks, nathan.
glenngv 08-05-2005, 03:02 AM <html>
<head>
<title>Birthday List</title>
<style type="text/css">
.header {
font-weight: bold;
}
</style>
<script type="text/javascript">
Date.prototype.getDiff = function(date, interval){
if (typeof date == "string"){
date = new Date(date);
}
if (isNaN(date) || !(date instanceof Date)){
return NaN; //invalid date passed
}
if (typeof interval == "undefined") interval = "ms"; //msec (default)
var diff = this - date; //alert(this+' - '+date+" = "+diff)//diff in msec
switch(interval.toLowerCase()){
case "s": //sec
diff = diff/1000; break;
case "n": //min
diff = diff/(1000*60); break;
case "h": //hr
diff = diff/(1000*60*60); break;
case "d": //day
diff = diff/(1000*60*60*24); break;
case "m": //month
diff = diff/(1000*60*60*24*30); break;
case "y": //year
diff = diff/(1000*60*60*24*365); break;
default:
; //msec
}
return Math.floor(diff);
}
var arrBday = [
['Bob', '7/23/1973', "http://www.bob.co.uk"],
['Glenn', '8/5/1989', "http://www.glenn.co.uk"],
['Nathan', '8/5/1999', "http://www.nathan.co.uk"],
['Peter', '8/18/1977', "http://www.peter.co.uk"],
['John', '8/19/1999', "http://www.john.co.uk"]
];
function getBdayList(numDays){
var bday,temp,idx,diff;
var today = new Date();
var bdayList = new Array();
for (var i=0;i<arrBday.length;i++){
bday = new Date(arrBday[i][1]);
if (isNaN(bday)) continue;
temp = new Date(today.getFullYear(), bday.getMonth(), bday.getDate(), 23, 59, 59, 999);
diff = temp.getDiff(today, "d");
if (diff >= 0 && diff <= numDays){
idx = bdayList.length;
bdayList[idx] = new Object();
bdayList[idx].name = arrBday[i][0];
bdayList[idx].bday = arrBday[i][1];
bdayList[idx].age = today.getDiff(bday, "y");
if (diff > 0) bdayList[idx].age = bdayList[idx].age + 1;
bdayList[idx].today = (diff == 0) ? true : false;
bdayList[idx].site = arrBday[i][2];
}
}
return bdayList;
}
function displayBdayList(){
var bdayList = getBdayList(14);
var len = bdayList.length;
var s1 = ""; //today's bday list
var s2 = ""; //next 2 week's bday list
if (len>0){
for (var i=0; i<len; i++){
if (bdayList[i].today){
if (s1 != ""){
s1 += ', <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
else{
s1 = '<span class="header">Today</span> <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
}
else{
if (s2 != ""){
s2 += ', <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' - ' + bdayList[i].bday + ' (' + bdayList[i].age + ')</a>';
}
else{
s2 = '<span class="header">Within next 14 days</span> <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' - ' + bdayList[i].bday + ' (' + bdayList[i].age + ')</a>';
}
}
}
}
else{
s1 = "No birthdays.";
}
document.write('<div>' + s1 + '</div><div>' + s2 + '</div>');
}
</script>
</head>
<body>
<h1>Birthday Celebrants</h1>
<div>
<script type="text/javascript">
displayBdayList();
</script>
</div>
</body>
</html>
1of6Billion 08-28-2005, 01:19 PM sorry wrong place for a question....
moved to http://www.codingforums.com/showthread.php?p=349746#post349746
nath192 10-27-2005, 03:09 PM <script type="text/javascript">
Date.prototype.getDiff = function(date, interval){
if (typeof date == "string"){
date = new Date(date);
}
if (isNaN(date) || !(date instanceof Date)){
return NaN; //invalid date passed
}
if (typeof interval == "undefined") interval = "ms"; //msec (default)
var diff = this - date; //alert(this+' - '+date+" = "+diff)//diff in msec
switch(interval.toLowerCase()){
case "s": //sec
diff = diff/1000; break;
case "n": //min
diff = diff/(1000*60); break;
case "h": //hr
diff = diff/(1000*60*60); break;
case "d": //day
diff = diff/(1000*60*60*24); break;
case "m": //month
diff = diff/(1000*60*60*24*30); break;
case "y": //year
diff = diff/(1000*60*60*24*365); break;
default:
; //msec
}
return Math.floor(diff);
}
var arrBday = [
['nathan', '5/2/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=5"],
['Crispy Dave', '4/23/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=6"],
['Snuggs', '10/30/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=7"],
['LizzieKitten', '5/1/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=8"],
['salimander', '1/7/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=9"],
['Farmer Phil', '10/24/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=10"],
['Andy', '8/30/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=12"],
['Becky', '2/24/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=11"],
['Rach', '8/19/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=13"],
['mandy', '7/12/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=14"],
['sarah', '1/20/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=15"],
['Tom', '4/12/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=17"],
['JonnyG', '1/29/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=20"],
['benny', '4/11/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=22"],
['Nicnic', '2/25/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=27"],
['Beth!', '8/7/1981', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=28"],
['Danny', '5/14/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=29"],
['Hannah', '8/10/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=30"],
['rec', '9/13/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=31"],
['Luke', '6/14/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=32"],
['Lil Franny', '4/5/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=34"],
['Catus', '4/09/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=35"],
['Kay', '7/22/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=36"],
['shing', '2/26/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=37"],
['Toad in the Soul', '8/3/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=40"],
['Emily', '7/30/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=41"],
['Rachx', '12/10/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=43"],
['Wrighty', '5/15/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=44"],
['ZsaZsa Bates', '4/18/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=45"],
['siani', '12/13/1982', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=47"],
['sam', '10/30/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=48"],
['DEREK', '4/13/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=49"],
['Erad', '6/8/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=51"],
['rachj', '6/26/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=52"],
['eot2', '12/2/1978', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=55"],
['olop1986', '4/29/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=56"],
['Aberads', '7/14/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=57"],
['chloe', '3/13/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=59"],
['Freddie', '8/20/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=60"],
['smeloise', '11/27/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=61"],
['Serena', '10/17/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=62"],
['Richard', '4/7/1982', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=63"],
['llion_evans', '1/5/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=64"],
['jo', '6/3/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=65"],
['Holly', '2/14/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=66"],
['reuben', '10/21/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=70"],
['Poppy', '3/7/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=72"],
['Ben', '10/30/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=77"],
['Sam R', '12/4/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=80"],
['Kevolution', '10/30/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=83"],
['crazychrist', '7/20/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=86"],
['alunjevans', '8/8/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=88"],
['smyrell', '12/9/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=90"],
['gtanswell', '11/9/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=91"],
['Mark Llanbadarn', '4/27/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=94"],
['jym1', '10/7/1982', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=95"],
['Pink_Jelly', '7/7/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=96"],
['joy', '12/14/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=99"],
['Beth Harrison', '3/13/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=102"],
['Little Miss Organized', '1/10/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=103"],
['Dave Smyrell', '12/9/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=104"],
['TomJ', '11/11/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=105"],
['Rhys Llwyd', '7/2/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=108"],
['Rosie', '7/2/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=110"],
['amk4', '9/25/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=111"],
['colin ailes', '7/20/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=112"],
['Jase', '2/9/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=114"],
['mla4', '7/29/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=113"],
['amy', '11/19/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=115"],
['bethan', '3/18/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=119"],
['steve ellis', '8/29/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=120"],
['helen', '8/24/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=121"],
['James', '10/4/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=122"],
['Em', '1/28/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=123"],
['deb', '4/2/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=125"],
['wacko', '8/21/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=129"],
['Elayne', '8/22/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=130"],
['Andrew', '10/9/1982', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=131"],
['bouncy_lil_rach', '6/5/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=132"],
['Jessica', '7/14/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=134"],
['mozzar', '8/25/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=137"],
['Alice', '8/7/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=138"],
['Darren Webster', '9/17/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=126"],
['Gemma', '11/9/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=161"],
['miniminime', '9/11/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=150"]
];
function getBdayList(numDays){
var bday,temp,idx,diff;
var today = new Date();
var bdayList = new Array();
for (var i=0;i<arrBday.length;i++){
bday = new Date(arrBday[i][1]);
if (isNaN(bday)) continue;
temp = new Date(today.getFullYear(), bday.getMonth(), bday.getDate(), 23, 59, 59, 999);
diff = temp.getDiff(today, "d");
if (diff >= 0 && diff <= numDays){
idx = bdayList.length;
bdayList[idx] = new Object();
bdayList[idx].name = arrBday[i][0];
bdayList[idx].bday = arrBday[i][1];
bdayList[idx].age = today.getDiff(bday, "y");
if (diff > 0) bdayList[idx].age = bdayList[idx].age + 1;
bdayList[idx].today = (diff == 0) ? true : false;
bdayList[idx].site = arrBday[i][2];
}
}
return bdayList;
}
function displayBdayList(){
var bdayList = getBdayList(14);
var len = bdayList.length;
var s1 = ""; //today's bday list
var s2 = ""; //next 2 week's bday list
if (len>0){
for (var i=0; i<len; i++){
if (bdayList[i].today){
if (s1 != ""){
s1 += ', <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
else{
s1 = '<span class="header">Today</span> <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
}
else{
if (s2 != ""){
s2 += ', <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
else{
s2 = '<span class="header">Within next 14 days</span> <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
}
}
}
else{
s1 = "No birthdays.";
}
document.write('<div>' + s1 + '</div><div>' + s2 + '</div>');
}
</script>
hi again glenn.
apologies for not thanking you before for your help. i have had the birthday script running on my site now for a while.
just one problem. often it displays the persons age incorrectly in brackets. it changes to sometimes being the correct and sometimes the wrong for no apparent reason.
do you have any idea why this would be please?
you can see the script in action at http://www.abercu.org.uk and by scrolling down to the bottom.
many thanks, nathan
nath192 11-08-2005, 01:20 PM please can someone help me with this? ....birthdays keep displaying wrong ages in brackets.. and im not sure where the code is incorrect.
thank you, nathan
Nischumacher 11-08-2005, 04:47 PM just change the arrBday to the following for a while to see what happens... save the previous value...
var arrBday = [ ['nathan', '11/1/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=5"], ['Crispy
Dave', '11/2/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=6"], ['Snuggs',
'11/3/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=7"],
['LizzieKitten', '11/4/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=8"], ['salimander',
'11/5/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=9"],
['Farmer Phil', '11/6/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=10"], ['Andy',
'11/7/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=12"],
['Becky', '11/8/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=11"], ['Rach',
'11/9/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=13"],
['mandy', '11/10/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=14"], ['sarah',
'11/11/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=15"],
['Tom', '11/12/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=17"], ['JonnyG',
'11/13/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=20"],
['benny', '11/14/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=22"], ['Nicnic',
'11/15/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=27"],
['Beth!', '11/16/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=28"], ['Danny',
'11/17/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=29"],
['Hannah', '11/18/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=30"], ['rec',
'11/19/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=31"],
['Luke', '11/20/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=32"], ['Lil
Franny', '11/21/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=34"], ['Catus',
'11/22/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=35"],
['Kay', '11/23/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=36"], ['shing',
'11/24/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=37"],
['Toad in the Soul', '11/25/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=40"], ['Emily',
'11/26/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=41"],
['Rachx', '11/27/1983',
"http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=43"], ['Wrighty',
'11/28/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=44"]
]; you will see that the people with their birthdays in the next 6 days are incremented by a year... why does this happen... i don't know... so until somebody comes up with the explaination and the right solution... here is mine that should work fine...
just make this change in your displayBdayList function from
if (diff > 0) bdayList[idx].age = bdayList[idx].age + 1;
to this
if (diff > 6) bdayList[idx].age = bdayList[idx].age + 1;
nath192 11-09-2005, 03:09 PM hey NS
thanks very much...seeems to have worked now. thanks for looking at it for me, nathan.
ps went to India when I was 16 about 6 years ago.. wonderful country!
Nischumacher 11-09-2005, 03:44 PM as i said... it will work... but i still maintain that it is not the best solution...
PS : never been to england :)
notcalvin 11-17-2005, 11:06 PM Is there a limit to the number of "birthday entries" these scripts can have?
I've tried both of the basic scripts from the beginning of this thread and have placed 43 entries into each one and get script errors when I try to have it on a webpage.
glenngv 11-18-2005, 01:52 AM What error message? You probably have misplaced quotes or brackets in the birthday array definition. Run the code in Firefox to easily spot the error.
notcalvin 11-18-2005, 02:55 AM :thumbsup: Yep. Had a comma missing.
That fixed it.
notcalvin 11-18-2005, 08:42 PM Oh, and how do I make it so that it doesn't show the actual birthday or just shows the month and day, but not the year?
Nischumacher 11-19-2005, 11:16 AM i think at the moment it is displaying the name along with the age... which is linked to respective individuals page...
it is not displaying there actual birthday...
if you don't want to display the age... then just remove bdayList[i].age from displayBdayList function.
notcalvin 11-20-2005, 12:24 AM Yeah, I did that.
What I'd really like it to do is display the name and the month/day of the birthday, but not the year.
I edited it enough to work for my needs currently - just displays the name of the person with a birthday today and within the next 14 days without showing any actual dates (or links for that matter).
swatisonee 12-15-2005, 04:19 AM Post moved by Swatisonee to Php- sorry about that..
FUNimations 01-14-2006, 04:07 PM hi
Is it possible to create the array of birthdays trough a subsciber box.
So you would have a field with
Name
Url
Birthday: DD/MM/YYYY
and upon submit it automaticly added to the array.
hotciats 01-26-2006, 01:20 AM hi glenn i'm new here, anyway i used these codes and it's pretty much working but can ask you how to edit this so that it will display all birthday celebrants per month not per day?
Well, how about this:
<script language="JavaScript">
var arrBday = [
['Bob','11/23/1973'],
['Peter','9/22/1977'],
['John','9/22/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='- NONE'
document.write("<h4>Today's Birtdays:</h4>"+strList)
}
displayBdayList(new Date());
</script>
glenngv 01-26-2006, 07:21 AM <html>
<head>
<title>Birthday List</title>
<script type="text/javascript">
//the bday array data can be generated from server-side
var arrBday = [
['Bob', '1/1/1973'],
['Glenn', '2/4/1989'],
['Nathan', '1/26/1999'],
['Peter', '1/27/1977'],
['John', '1/26/1999']
//...and so on (last entry must not have a trailing comma)
];
function getBdayList(month){
var bday, idx;
var today = new Date();
var bdayList = new Array();
for (var i=0;i<arrBday.length;i++){
bday = new Date(arrBday[i][1]);
if (isNaN(bday)) continue;
if (month == bday.getMonth()){
idx = bdayList.length;
bdayList[idx] = new Object();
bdayList[idx].name = arrBday[i][0];
bdayList[idx].bday = bday;
bdayList[idx].age = today.getFullYear() - bday.getFullYear();
}
}
if (bdayList.length > 0){ //sort asc by birthdate
bdayList.sort(
function(a, b){
if (a.bday.getDate() < b.bday.getDate()) return -1;
if (a.bday.getDate() > b.bday.getDate()) return 1;
return 0;
}
);
}
return bdayList;
}
function displayBdayList(){
var arrMonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "August", "October", "November", "December");
var month = new Date().getMonth();
var date = new Date().getDate();
var monthName = arrMonth[month];
var bdayList = getBdayList(month);
var len = bdayList.length;
var s = "<h1>Birthday Celebrants for the Month of " + monthName + "</h1>";
if (len>0){
s += '<ul>';
for (var i=0; i<len; i++){
//no age
s += '<li' + ((date == bdayList[i].bday.getDate())?' class="bdayToday"':'') + '><strong>' + bdayList[i].name + "</strong> - " + monthName + " " + bdayList[i].bday.getDate() + "</li>";
//with age
//s += '<li' + ((date == bdayList[i].bday.getDate())?' class="bdayToday"':'') + '><strong>' + bdayList[i].name + "</strong> - " + monthName + " " + bdayList[i].bday.getDate() + " (" + bdayList[i].age + ")</li>";
}
s += '</ul>';
}
else{
s += "No birthday celebrant for this month.";
}
document.write(s);
}
</script>
<style type="text/css">
body {
font:14px Verdana;
}
/*display style when bday is today*/
.bdayToday {
color: red;
}
</style>
</head>
<body>
<script type="text/javascript">
displayBdayList();
</script>
</body>
</html>
hotciats 02-02-2006, 08:18 AM Thanks very much glenn, it took me a hard a time to find this script not knowing that I can only find it here with your help.
CubsHub 03-10-2006, 08:31 PM To use with a database?
I have a database with over 1500 birthday's...
[firstname] [lastname] [birthday]
Is there any way to edit this script to work with a mysql database?
would rather use php with it, I realize this thread is in the javascript section, but please let me know.
Thanks!
glenngv 03-16-2006, 05:23 AM To use with a database?
I have a database with over 1500 birthday's...
[firstname] [lastname] [birthday]
Is there any way to edit this script to work with a mysql database?
would rather use php with it, I realize this thread is in the javascript section, but please let me know.
Thanks!
Just generate this javascript array from php:
//the bday array data can be generated from server-side
var arrBday = [
['Bob', '1/1/1973'],
['Glenn', '2/4/1989'],
['Nathan', '1/26/1999'],
['Peter', '1/27/1977'],
['John', '1/26/1999']
//...and so on (last entry must not have a trailing comma)
];
MiLLion 03-26-2006, 02:57 PM I'm gonna try to make a fetch from a mysql database when i get home. I can use <?php tags inside the birthdaylist array, right?
MiLLion 03-26-2006, 05:23 PM Hm... this isnt working to me...
I tried to use this code:
<script type="text/javascript">
//the bday array data can be generated from server-side
var arrBday = [
['Emelie', '8/26/1990'],
['Truls', '9/4/1989'],
['Tobias', '5/26/1989'],
['Andrea', '4/20/1990'],
['Truls', '9/4/1989'],
['Magnus', '3/7/1990'],
['Kristine', '5/12/1990'],
['Rebecca', '3/24/1990'],
['Hedda', '1/15/1987'],
['Petter', '5/25/1989'],
['Erlend', '10/24/1989'],
['Beate', '8/27/1990'],
['Karianne', '11/30/1990'],
['Karianne', '12/15/1990'],
['Kristina', '2/20/1990'],
['Cathrine', '11/2/1987'],
['Magnus', '4/23/1978'],
['Daniel', '7/12/1989'],
['KES', '2/13/1970'],
['Kjetil', '7/12/1989'],
['Tessa', '7/27/1990'],
['Aurora', '6/8/1990'],
['Andreas', '8/14/1986'],
['Camilla', '11/17/1989'],
['Julia', '4/21/1987'],
<?php
$conn = mysql_connect("localhost","username","password");
mysql_select_db(username) or die(mysql_error());
$getposts = mysql_query("SELECT * FROM birthdays");
while($r=mysql_fetch_array($getposts)){
$name= $r["name"];
$date= $r["date"];
echo "['$name', '$date'],";
}
?>
['Busk', '5/12/1990']
//...and so on (last entry must not have a trailing comma)
];
function getBdayList(month){
var bday, idx;
var today = new Date();
var bdayList = new Array();
for (var i=0;i<arrBday.length;i++){
bday = new Date(arrBday[i][1]);
if (isNaN(bday)) continue;
if (month == bday.getMonth()){
idx = bdayList.length;
bdayList[idx] = new Object();
bdayList[idx].name = arrBday[i][0];
bdayList[idx].bday = bday;
bdayList[idx].age = today.getFullYear() - bday.getFullYear();
}
}
if (bdayList.length > 0){ //sort asc by birthdate
bdayList.sort(
function(a, b){
if (a.bday.getDate() < b.bday.getDate()) return -1;
if (a.bday.getDate() > b.bday.getDate()) return 1;
return 0;
}
);
}
return bdayList;
}
function displayBdayList(){
var arrMonth = new Array("Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "August", "Oktober", "November", "Desember");
var month = new Date().getMonth();
var date = new Date().getDate();
var monthName = arrMonth[month];
var bdayList = getBdayList(month);
var len = bdayList.length;
var s = "<h3>Bursdager i " + monthName + "</h3>";
if (len>0){
for (var i=0; i<len; i++){
//no age
// s += '<li' + ((date == bdayList[i].bday.getDate())?' class="bdayToday"':'') + '><strong>' + bdayList[i].name + "</strong> - " + monthName + " " + bdayList[i].bday.getDate() + "</li>";
//with age
s += '· ' + ((date == bdayList[i].bday.getDate())?' ':'') + '<strong>' + bdayList[i].name + "</strong> - " + monthName + " " + bdayList[i].bday.getDate() + " (" + bdayList[i].age + ")<br>";
}
}
else{
s += "Ingen bursdager denne måneden.";
}
document.write(s);
}
</script>
But it doesnt work...
I have a databasetable called "birthdays" and with 3 rows: id, name and date.
Can anyone see whats wrong? I don't get any errormessages, it just don't display anything
seanko 04-17-2006, 07:25 AM hi glenn. i really admire your script! it is awesome. Just one thing happened to come accross my mind.. Can you please make me a script like you made for nathan, but just change it a bit and if possible, make the array in a seperate file:confused::
can you change it so that it displays the birthdays in the next 7 days.
when it displays somebody's birthday, can you change the format to:[name] turns [age] today
[name] turns [age] in 4 days
also as i mentioned above, can make the script read another file with this array?
Finally, if possible, can you write it in php:confused::confused::confused:
xxlxxl 05-04-2006, 05:19 AM Glenn, i'd like to use the code you mentioned wrote in your second post, but using the DD/MM configuration and without displaying the year of birth, just day and month. Last thing, i'd like it to display the birthdays in the next 7 days.
thanks, congrats
gmn17 05-04-2006, 05:47 AM Glenn, i'd like to use the code you mentioned wrote in your second post, but using the DD/MM configuration and without displaying the year of birth, just day and month. Last thing, i'd like it to display the birthdays in the next 7 days.
thanks, congrats
yea! me too! If I type in the year, can I make it go away?
"Last thing, i'd like it to display the birthdays in the next 7 days."
Not hard to do, but not easy, I'd like it to do lots of things, Holy Hell!, Where do people like you come from? I know you understand the year is not shown in the format you have gushed over, but don't abuse your right to post here for help.
mensa_dropout 05-07-2006, 12:10 AM ...using the DD/MM configuration...[and] display the birthdays in the next 7 days.
I'm not sure this is exactly what you were looking for, but I thought it would be neat to make the mods. It works for me in firefox and IE.
<html>
<head>
<title>Birthday List</title>
<script type="text/javascript">
//the bday array data can be generated from server-side
var arrBday = [
['Aunt B.', '5/6'],
['Goober', '5/7'],
['Andy', '5/8'],
['Otis', '5/9'],
['Earnest T.', '5/10'],
['Opey', '5/11'],
['Barney', '5/12'],
['Thelma Lu', '5/13']
//...and so on (last entry must not have a trailing comma)
];
function getBdaysThisWeek(){
var arrMonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
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()];
}
}
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();
//have to override time so entire day will be valid
today.setHours(0,0,0,0);
//if the birthday has already occurred in the year, increment to the next year
if (bday < today)
bday.setFullYear(bday.getFullYear() + 1);
// get ms between dates (UTC) and make into "difference" date
var iDiffMS = bday.valueOf() - today.valueOf();
//divide iDiffMS by 1000, Seconds, Minutes, Hours
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>Birthday Celebrants for this week:</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"':'')+ '>\
<strong>' + bdayList[i].name + '</strong> - '
+ bdayList[i].month + ' ' + bdayList[i].bday.getDate() + '</li>';
}
s += '</ul>';
}
else{
s += "No birthday celebrant for this week.";
}
document.write(s);
}
</script>
<style type="text/css">
body {
font:14px Verdana;
}
/*display style when bday is today*/
.bdayToday {
color: red;
}
</style>
</head>
<body>
<script type="text/javascript">
displayBdayList();
</script>
</body>
</html>
xxlxxl 05-07-2006, 08:15 PM thanks a lot, it wasn't really what I wanted, but i managed to make it work the way I wanted due to the way you wrote it because i don't know anything about scripts.
seanko 05-20-2006, 04:36 AM can someone please help me make a change to this code because i am terrible at javascript!!:)
i would like it to display the celebrant's age and also when their birthday is "today", i would like it to say "[name] celebrates their birthday today" and it can be red as it is.
can someone plz help me?:confused:
<html>
<head>
<title>Birthday List</title>
<script type="text/javascript">
//the bday array data can be generated from server-side
var arrBday = [
['Aunt B.', '5/6'],
['Goober', '5/7'],
['Andy', '5/8'],
['Otis', '5/9'],
['Earnest T.', '5/10'],
['Opey', '5/11'],
['Barney', '5/12'],
['Thelma Lu', '5/13']
//...and so on (last entry must not have a trailing comma)
];
function getBdaysThisWeek(){
var arrMonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
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()];
}
}
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();
//have to override time so entire day will be valid
today.setHours(0,0,0,0);
//if the birthday has already occurred in the year, increment to the next year
if (bday < today)
bday.setFullYear(bday.getFullYear() + 1);
// get ms between dates (UTC) and make into "difference" date
var iDiffMS = bday.valueOf() - today.valueOf();
//divide iDiffMS by 1000, Seconds, Minutes, Hours
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>Birthday Celebrants for this week:</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"':'')+ '>\
<strong>' + bdayList[i].name + '</strong> - '
+ bdayList[i].month + ' ' + bdayList[i].bday.getDate() + '</li>';
}
s += '</ul>';
}
else{
s += "No birthday celebrant for this week.";
}
document.write(s);
}
</script>
<style type="text/css">
body {
font:14px Verdana;
}
/*display style when bday is today*/
.bdayToday {
color: red;
}
</style>
</head>
<body>
<script type="text/javascript">
displayBdayList();
</script>
</body>
</html>
xp_mahesh 06-10-2006, 07:11 AM Hi Guys,
I want the above code which will retrive Name,Date of birth, Email-id (when user click the name it will be redirected to outlook to send a mail) from an excel sheet. And also if the Birthday comes on sunday, it must shows that birthday list on saturday itself. Please give the code for it. Awaiting for the reply....
MaheshKumar
nadweb 06-19-2006, 07:40 PM Hello,
I was searching in Google for a birthday script to use on my website and I came across this forum. I think I will be adding it to my list of forums that I visit regularly for it has so much of smart discussions that benefit me and my work.
I wanted to have my website users , after they submit my website form to be taken to another little form that asks them to enter their birthday, name, and email.
I wanted this data to be picked up by a script and on each person's birthday the script will send a customized bday and keep in touch card in an email to that person's email.
Can anyone help me with that? My server accepts PHP and not ASP.
I know a little about programming and I've worked with codes before. If anyone can help me I would appreciate it, maybe show me a site that has similar scripts to do this job.
If anyone is interested in helping as a paid developer I have no objection just contact me to discuss the price we can go from there.
Thanks
Nad
bkg4him 08-23-2006, 05:47 PM I've got an existing Intranet set up at work. The guy that set it up is no longer here. It has a birthday list that shows birthdays for the next two weeks, and if today is someone's birthday, then it shows up in red. This works great for us. So well that I wanted to do the very same thing with everyone's employment anniversary. I tried copying the code for bday and replacing it with Ann for Anniversary, but it still displays the birthdays. Any idea how to essentially run two birthday lists at once? The birthday list does not show age, but on the Anniversary, I could put the year they started employment rather than year of birth so it would be displayed 'John Doe - August 28 - 5 years'.
The code looks identical to what mensa_dropout and seanko posted a few posts up.
I'm new to this web site design, java scripting etc. and any help would be much appreciated.
Thank you, thank you, thank you!!!
A problem is that Seanko in his post on 05-20-2006 didn't have an option of showing the age of the one who is celebrating the birthday. The code doesn't contain any info of the year of birth either.
So, if I have the script of 05-20-2006, what do I have to do to have the age of the birthday child be displayed?
CSky
vanbao 01-14-2007, 07:30 PM I am a newbie here and I have been looking for birthday script for a long time but with no luck.
What I want to do is have a script that will read a field from a flat file containing the peoples names and birtdays. If this script can also send an email that that person upon their birthday it would be perfect.
Can some please help me with this.
Thanks in advance.
Nick67 01-14-2007, 10:37 PM Hi, what means with this line below?
//the bday array data can be generated from server-side
var arrBday = [
Is it possible to save the javascript in post #7 in this thread to a js.file or a flat-file instead?
NYGal98 07-09-2008, 09:58 PM Hi there,
I hope someone out there can still help with this script. I tried it and it worked perfectly as is. Then I started customizing it by changing it to "Happy Birthday to:" and taking out the age display. It still worked fine. Then I changed the names and put today's date to test it and it still worked fine.
Then I copied the list entries so I could display more and that's when it stopped working. I cut and pasted the same list into it but it comes up blank now.
Is there a limit to how many names/birthdays can be on the list? Is there a way I can get it to watch a list of about 150 names throughout the year?
Thanks very much in advance.
Danman28 07-24-2008, 03:36 PM Hi glenngv
Your script is great it is working very well, accept that it only will work in mozilla and not IE.
i getting the following error:
'arrBday[...].1' is empty or no object
Code: 0
here is your script:
Date.prototype.getDiff = function(date, interval){
if (typeof date == "string"){
date = new Date(date);
}
if (isNaN(date) || !(date instanceof Date)){
return NaN; //invalid date passed
}
if (typeof interval == "undefined") interval = "ms"; //msec (default)
var diff = this - date; //alert(this+' - '+date+" = "+diff)//diff in msec
switch(interval.toLowerCase()){
case "s": //sec
diff = diff/1000; break;
case "n": //min
diff = diff/(1000*60); break;
case "h": //hr
diff = diff/(1000*60*60); break;
case "d": //day
diff = diff/(1000*60*60*24); break;
case "m": //month
diff = diff/(1000*60*60*24*30); break;
case "y": //year
diff = diff/(1000*60*60*24*365); break;
default:
; //msec
}
return Math.floor(diff);
}
var arrBday =[
['name1', '7/22/1981', "http://wesite.com"],
['name2', '9/20/1983', "http://website.com"],
['name3', '11/9/1985', "http://website.com"],
['name4', '11/9/1985', "http://website.com"],
['name5', '12/7/1980', "http://website.com"],
['name6', '12/2/1980', "http://website.com"],
['name7', '10/10/1983', "http://website.com"],
['name8', '7/26/1986', "http://website.com"],
];
function getBdayList(numDays){
var bday,temp,idx,diff;
var today = new Date();
var bdayList = new Array();
for (var i=0;i<arrBday.length;i++){
bday = new Date(arrBday[i][1]);
if (isNaN(bday)) continue;
temp = new Date(today.getFullYear(), bday.getMonth(), bday.getDate(), 23, 59, 59, 999);
diff = temp.getDiff(today, "d");
if (diff >= 0 && diff <= numDays){
idx = bdayList.length;
bdayList[idx] = new Object();
bdayList[idx].name = arrBday[i][0];
bdayList[idx].bday = arrBday[i][1];
bdayList[idx].age = today.getDiff(bday, "y");
if (diff > 6) bdayList[idx].age = bdayList[idx].age + 1;
bdayList[idx].today = (diff == 0) ? true : false;
bdayList[idx].site = arrBday[i][2];
}
}
return bdayList;
}
function displayBdayList(){
var bdayList = getBdayList(14);
var len = bdayList.length;
var s1 = ""; //today's bday list
var s2 = ""; //next 2 week's bday list
if (len>0){
for (var i=0; i<len; i++){
if (bdayList[i].today){
if (s1 != ""){
s1 = ', <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
else{
s1 = '<span class="bdayToday">Today:</span> <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
}
else{
if (s2 != ""){
s2 = ', <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
else{
s2 = '<span class="bdayLater">Within 14 Days:</span> <a href="' + bdayList[i].site + '">' + bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
}
}
}
}
else{
s1 = '<span class="bdayLater">No Birthdays.</span>';
}
document.write('<div>' + s1 + '</div><div>' + s2 + '</div>');
}
thanks for helping me out if you can
i will really appreciated it.
best regards,
Danman28
|
|