www.webdeveloper.com
Results 1 to 7 of 7

Thread: [RESOLVED] Date function help

  1. #1
    Join Date
    Aug 2011
    Posts
    18

    resolved [RESOLVED] Date function help

    I am trying to come up with a function that will display the full 4 digit year inside of a footer div. I know how to do it with document.write getFullYear() call but i need to apply it in a function.

    Any ideas?

  2. #2
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    use innerHTML instead of document.write

  3. #3
    Join Date
    Aug 2011
    Posts
    18
    I have since come across this code:

    HTML Code:
    <p>&copy; <script language="JavaScript" type="text/javascript">
        now = new Date
        theYear=now.getYear()
        if (theYear < 1900)
        theYear=theYear+1900
        document.write(theYear)
    </script> Somecompany, Inc. All Rights reserved.</p>
    I need to create this as a function that will be placed in an external js file. It will need to be called on several pages within the company website.

    My line of thinking is this:

    HTML Code:
    <script language="JavaScript" type="text/javascript">
        function copyDate(){
        now = new Date
        theYear=now.getYear()
        if (theYear < 1900)
        theYear=theYear+1900
        document.write(theYear)
    }
    </script>
    
    
    <p>&copy; document.inner.HTML(copyDate) Somecompany, Inc. All Rights reserved.</p>

  4. #4
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    Code:
    
    <p>&copy; <span id="copydate"></span> Somecompany, Inc. All Rights reserved.</p>
    <script type="text/javascript">
        now = new Date
        theYear=now.getYear()
        if (theYear < 1900)
        theYear=theYear+1900
        document.getElementById('copydate').innerHTML= theYear
    </script>
    Last edited by DanInMA; 11-08-2011 at 03:02 PM. Reason: woops

  5. #5
    Join Date
    Aug 2011
    Posts
    18
    Its not working.

  6. #6
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    woops sorry, I edited the post.

  7. #7
    Join Date
    Aug 2011
    Posts
    18
    I am lost now. Should I just use the last line that you changed?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles