Forum Moderators: open

Message Too Old, No Replies

variables in document.writeln()

         

sebbothebutcher

11:38 am on Apr 12, 2004 (gmt 0)

10+ Year Member



i want to create a link depending on the date (eg. if the date is the 2nd of may 2004 the link links to "252004.html". how can i insert these variables into document.writeln?
please help!

Alternative Future

11:54 am on Apr 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi sebbothebutcher,

Is this what you are trying to do?

<script language="JavaScript">
var date = new Date();
var d = date.getDate();
var day = (d < 10)? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10)? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000)? yy + 1900 : yy;
year = (year+"").substring(2,4)

document.writeln(day,month,year+".html");
</script>

to get a 4 digit year just remove or uncomment the substring function!

-George

Alternative Future

11:58 am on Apr 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This one takes care of the 0 in both day and month:

<script language="JavaScript">
var date = new Date();
var d = date.getDate();
var m = date.getMonth() + 1;
var yy = date.getYear();
var year = (yy < 1000)? yy + 1900 : yy;
year = (year+"").substring(2,4)

document.writeln(d,m,year+".html");
</script>

-George

sebbothebutcher

12:03 pm on Apr 12, 2004 (gmt 0)

10+ Year Member



yes, this is exactly what i wanted! thank you very much!