Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Posts
    336
    Thanks
    43
    Thanked 2 Times in 2 Posts

    How do I add a "This page was last updated on.." to my site?

    Is there a method of automatically adding a "this page was last update on..." to my site?

    The BBC use one on their site http://news.bbc.co.uk/

    I know I can just type in the date and time, but I was wondering if there is an automated method for whenever I update anything?

  • #2
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    Yes this is possible via PHP, and common amongst many CMS (content-management-systems).

    You can either learn PHP to retrieve a value on when a document is updated or use an already available Blogging system (Wordpress/Blogger) of some sort which it is common.

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Dreamweaver had a function to do this once upon a time, if you happen to be using that. I don't use it any more, though, so don't know if it's still there.

    Also, PHP's filemtime() would work nicely if your server is PHP friendly. The others probably have something similar.

  • #4
    Regular Coder
    Join Date
    Sep 2008
    Location
    Oklahoma
    Posts
    249
    Thanks
    11
    Thanked 13 Times in 13 Posts
    this is from http://us3.php.net/manual/en/function.filemtime.php

    PHP Code:
    <?php
    // outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.

    $filename 'somefile.txt';
    if (
    file_exists($filename)) {
        echo 
    "$filename was last modified: " date ("F d Y H:i:s."filemtime($filename));
    }
    ?>

  • #5
    Regular Coder
    Join Date
    Aug 2005
    Location
    MS
    Posts
    845
    Thanks
    11
    Thanked 79 Times in 77 Posts
    Simple JavaScript:
    Code:
    <script type="text/javascript">
    
    function lastModified() {
      var modiDate=new Date(document.lastModified)
      var showAs=modiDate.getDate()+ "-" +(modiDate.getMonth()+1)+ "-" +modiDate.getYear();
    return showAs }
    
    function GetTime() {
      var modiDate = new Date();
      var Seconds
    
        if (modiDate.getSeconds() < 10)
        {
    	    Seconds = "0" + modiDate.getSeconds();
    	  } else {
    	    Seconds = modiDate.getSeconds();
    	  }
    
      var modiDate = new Date();
      var CurTime =  modiDate.getHours() + ":" + modiDate.getMinutes() + ":" + Seconds
      return CurTime }
    
      document.write ("This page was last updated on ")
      document.write (lastModified() + " @ " + GetTime() );
    
    </script>
    Goes in between body tags, but if using it as an external js file, then link and style where you want it to appear.
    Last edited by Major Payne; 11-05-2008 at 04:06 AM.
    ☠ ☠RON☠ ☠

  • #6
    Regular Coder
    Join Date
    Oct 2005
    Posts
    336
    Thanks
    43
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Major Payne View Post
    Simple JavaScript:
    Code:
    <script type="text/javascript">
    
    function lastModified() {
      var modiDate=new Date(document.lastModified)
      var showAs=modiDate.getDate()+ "-" +(modiDate.getMonth()+1)+ "-" +modiDate.getYear();
    return showAs }
    
    function GetTime() {
      var modiDate = new Date();
      var Seconds
    
        if (modiDate.getSeconds() < 10)
        {
    	    Seconds = "0" + modiDate.getSeconds();
    	  } else {
    	    Seconds = modiDate.getSeconds();
    	  }
    
      var modiDate = new Date();
      var CurTime =  modiDate.getHours() + ":" + modiDate.getMinutes() + ":" + Seconds
      return CurTime }
    
      document.write ("This page was last updated on ")
      document.write (lastModified() + " @ " + GetTime() );
    
    </script>
    Goes in between body tags, but if using it as an external js file, then link and style where you want it to appear.
    This code just updates the time whenever the Refresh button in a browser is clicked, so it isnt a true time-stamp. But thankyou for your reply

  • #7
    Regular Coder
    Join Date
    Nov 2008
    Posts
    175
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Code:
    <script>
    document.write('text goes here')
    </script>
    <script>
    var modifieddate=document.lastModified
    document.write(modifieddate)
    </script>
    As mentioned before goes in the body tags, should work

  • #8
    Regular Coder Donkey's Avatar
    Join Date
    Sep 2003
    Location
    Blackfield UK
    Posts
    312
    Thanks
    1
    Thanked 36 Times in 36 Posts
    Surely the easiest way is to use server side includes?

    e.g. for your index page rename the page "index.shtml" then add the following code
    Code:
    Last modified <!--#config timefmt="%d %B %Y" --><!--#flastmod file="index.shtml" -->.
    This will output in the following format:
    Last modified 06 November 2008.
    " 90% of everything is crud" - Theodore Sturgeon
    Filthy Beast - a 60's Rock Band

  • Users who have thanked Donkey for this post:

    moss2076 (11-07-2008)

  • #9
    Regular Coder
    Join Date
    Sep 2008
    Location
    Oklahoma
    Posts
    249
    Thanks
    11
    Thanked 13 Times in 13 Posts
    felt the need to repost, since it seems everyone skipped my first post

    and i changed it so it outputs "This page was last updated on November 06 2008 14:11:22" or whatever date and time the file was last changed.

    PHP Code:
    <?php 
    // outputs e.g.  This page was last updated on November 06 2008 14:11:22 

    $filename 'somefile.txt'
    if (
    file_exists($filename)) { 
        echo 
    "This page was last updated on " date ("F d Y H:i:s"filemtime($filename)); 

    ?>

  • #10
    Regular Coder
    Join Date
    Feb 2007
    Location
    Canada
    Posts
    924
    Thanks
    10
    Thanked 56 Times in 55 Posts
    PHP Code:
    <?php 
    // outputs e.g.  This page was last updated on November 06 2008 14:11:22 

        
    echo "This page was last updated on " date ("F d Y H:i:s"filemtime($_SERVER['SCRIPT_FILENAME'])); 

    ?>

  • #11
    Regular Coder
    Join Date
    Oct 2005
    Posts
    336
    Thanks
    43
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Donkey View Post
    Surely the easiest way is to use server side includes?

    e.g. for your index page rename the page "index.shtml" then add the following code
    Code:
    Last modified <!--#config timefmt="%d %B %Y" --><!--#flastmod file="index.shtml" -->.
    This will output in the following format:
    I had been using Dreamweavers code up until now -
    Code:
    <!-- #BeginDate format:fcAm1a -->Thursday, November 6, 2008 11:33 PM<!-- #EndDate -->
    , this works, but it only saves the date and time when index.html is saved on my computer. It doesnt save the date and time when I update the page to my server, which is what I want.

    I havent tried the other examples that have been posted as Im waiting for new hosting, so hopefully I will be able to give them a go later today.

    Many thanks everyone for your replies.

  • #12
    Regular Coder Donkey's Avatar
    Join Date
    Sep 2003
    Location
    Blackfield UK
    Posts
    312
    Thanks
    1
    Thanked 36 Times in 36 Posts
    It doesnt save the date and time when I update the page to my server, which is what I want.
    This is nothing to do with dreamweaver? The code I posted does what you want provided your host allows server side includes. Most do.
    " 90% of everything is crud" - Theodore Sturgeon
    Filthy Beast - a 60's Rock Band

  • #13
    Regular Coder
    Join Date
    Sep 2008
    Location
    Oklahoma
    Posts
    249
    Thanks
    11
    Thanked 13 Times in 13 Posts
    the post i made above works perfectly

  • #14
    Regular Coder
    Join Date
    Oct 2005
    Posts
    336
    Thanks
    43
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Donkey View Post
    Surely the easiest way is to use server side includes?

    e.g. for your index page rename the page "index.shtml" then add the following code
    Code:
    Last modified <!--#config timefmt="%d %B %Y" --><!--#flastmod file="index.shtml" -->.
    This will output in the following format:
    You are totally correct. I have changed the %d %B %Y to just %c which gives 11/07/08 20:27:49.

    Many thanks
    Last edited by moss2076; 11-07-2008 at 09:29 PM.


  •  

    LinkBacks (?)

    1. 04-18-2014, 02:14 AM

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •