Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Greetings again! I did say I would be back soon, hehe.
My question this time is, if u want to link something to a link which changes daily, for example:
www.mypage.com/images/20040608.gif
. Ive come up with the idea that I can use javascript for this, here is the script Ive got so far:
<script type="text/javascript">
var d = new Date()
document.write(d.getFullYear())
document.write(d.getMonth() + 1)
document.write(d.getDate())
</script>First problem:
the Date it gives for 20040608 is 200468. Any idea's how to get it to 20040608? My research shows something on the lines of:
new Date(yy,mm,dd)
which should get the month (mm) and day (dd) as a two digit number, but I can't get this to work.Secondly, any idea how to link to sucha page? I was thinking something on the lines of turning 2004, 06, 08 to strings, concatenate them together, and finally concat the whole thing to the base url, like:
myLink = "http://www.mysite.com/images/"++FullYear.toString()++month.toString()++day.toString().And then href to myLink. Any ideas on how to get this working? Thanx,
Michele

Uhmm, it probably would, but considering the
trouble I've had with PHP (I can't even get
the REMOTE_ADRR! It gets the servers IP!) I
think for the moment I'm stuck with
javascript.
Michele

This:
var today = new Date()
var day = today.getDate()
var month = today.getMonth() + 1
var year = today.getYear()
day = day.toString()
month = month.toString()
year = year.toString()
if (day.length == 1) {day = '0' + day}
if (month.length == 1) {month = '0' + month}
document.write(year + month + day)will output the date as you want.
I have only added a litte 'test' to check if the day and month have 1 digit. I have searched my JavaScript-bible, but couldnt find another solution.

PERFECT! Thank you so much! Now I can finish that off! I've ben trying to code a really constipated version with if loops to check the the 0's, lol.
Thanx again,
Michele

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |