Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

daily link

a different link for each month + day

5:42 am on Sep 6, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2006
votes: 0

I'm having trouble with what seems like it should be an easy script to write (but then, I'm a designer not a programmer). What I want to do is to serve up today's date with a different link for each day of the year (366 different links depending on today's date). I only care about month and day, not the year (September 5 will always link to a certain page, no matter the year; "September 5" will always be the anchor text for that date). I'm having trouble with the "and" operator in the condition "if it's september and it's day 5." Thanks for any help.
1:34 pm on Sept 8, 2008 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
votes: 20

Perhaps something along these lines:

var today = new Date(); 
var dayOfMonth = today.getDate() - 1;
var month = today.getMonth();
var links = [
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Jan
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29], // Feb
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Mar
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30], // Apr
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // May
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30], // Jun
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Jul
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Aug
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30], // Sep
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31], // Oct
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30], // Nov
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31] // Dec

Replace the numbers with the desired link values. All I've done is created an array that has 12 values (1 for each month). The 12 values happen to be another array containing the number of items that correspond to the number of days in the month. I then used the current month and day of the month to index into my top level array and its nested array.
3:15 pm on Sept 18, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2006
votes: 0

Thanks, Fotiman! That's interesting -- I'll give it a try.