Web Analytics Made Easy -
StatCounter Having a Link Change With the Date - CodingForum


No announcement yet.

Having a Link Change With the Date

  • Filter
  • Time
  • Show
Clear All
new posts

  • Having a Link Change With the Date

    Hello all,

    This is my first post of what will surely be many on these forums. Hopefully I can find the help I need.

    I have a link on my site that points to a page my client has asked to change daily. Basically, it is a report that is updated each morning and posted first thing. The format of the link is http://www.domain.com/2004/feb/0216_print.ppt. As you can see, it points to a powerpoint presentation. The format of the URL stays the same, so I suspect I require javascript code to determine the year, month and date and then insert it into the link in some manner.

    First off, does this make any sense at all? I hope I described it clearly.

    Second, is this possible?

    And third, anyone have any ideas how to do this?

    Any help would be greatly appreciated.

  • #2
    Javascript can do it. The problem is that javascript uses the date from the individuals PC that is viewing the page and if they do not have their date and time set correctly or are in another time zone then you will not get a correct date. You should use a Server Side language such as Perl or PHP to perform this function because they can use the date that is set on the server. Good Luck.


    • #3
      Well, the page is actually a PHP page, so that could be an option.

      The site is housed on an Intranet where the client's machine have their date and such controlled by the server anyway, so that's not a real concern of mine. I see your point, but I would be satisfied with a Javascript solution (or a PHP one, either or...).


      • #4
        Date.prototype.getMonthString = function() {
        	var months = [
        	return months[this.getMonth()];
        function createLink() {
        	var now = new Date();
        	var year = now.getFullYear();
        	var monthstr = now.getMonthString();
        	var monthnum = (now.getMonth() < 10) ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1);
        	var date = (now.getDate() < 10) ? "0" + now.getDate() : now.getDate();
        	document.write("<a href=\"http://www.domain.com/" + year + "/" + monthstr + "/" + monthnum + "" +
        		date + "_print.ppt\">My Link</a>");
        Then, call the createLink() function wherever you wish to put the link.

        Hope that helps!

        Happy coding!


        • #5
          Wow, that works perfect. Thanks a lot for your help.

          However, I was just informed that I need to first test and check if the document is even there before sending the user to a dead link, and I'm told this should be in PHP. I realize this is no longer the correct forum for PHP help though.


          • #6
            Yes you are right you should post this in the PHP forum. In PHP you can use file_exists("file name") to check for the existence of a file. Here is a link that gives a better explanation and on the side bar some more methods dealing with files. Good Luck.