Welcome to TalkGraphics.com
Page 1 of 3 123 LastLast
Results 1 to 10 of 26
  1. #1
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Unhappy Dynamic Date Script

    Hi Folks. I'm returning to Web Designer after a few years away and I'm in the middle of designing a fairly straightforward site.

    Historically, I've always had a bit of javascript code (that I've copied and pasted from my previous web creations and that I found somewhere on the 'net) that simply shows the day/date - and it changes daily to automagically to show the current day/date.

    I came to use it on my new site and decided I needed to align the text to the right. Does anyone know what I need to add to the code to allow me to 'align it right'?

    Thanks in advance!

    <style>
    .mydate {
    font: 10px arial;
    color: white;
    }
    </style>
    <SCRIPT LANGUAGE="Javascript"><!--

    // Get today's current date.
    var now = new Date();

    // Array list of days.
    var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thu rsday','Friday','Saturday');

    // Array list of months.
    var months = new Array('January','February','March','April','May',' June','July','August','September','October','Novem ber','December');

    // Calculate the number of the current day in the week.
    var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

    // Calculate four digit year.
    function fourdigits(number) {
    return (number < 1000) ? number + 1900 : number;
    }

    // Join it all together
    today = days[now.getDay()] + ", " +
    months[now.getMonth()] + " " +
    date + ", " +
    (fourdigits(now.getYear())) ;

    // Print out the data.
    document.write('<span class="mydate">' + today + '</span>');
    //--></SCRIPT>
    Last edited by SteveP; 30 August 2016 at 06:07 AM. Reason: typo in code
    Thanks

    Steve
    Kettering UK

  2. #2
    Join Date
    Aug 2000
    Location
    Harwich, Essex, England
    Posts
    21,916

    Default Re: Dynamic Date Script

    Works fine for me Steve. You probably forgot to hit Apply after changing the text size
    Attached Files Attached Files
    Egg

    Intel i7 - 4790K Quad Core + 16 GB Ram + NVIDIA Geforce GTX 1660 Graphics Card + MSI Optix Mag321 Curv monitor
    + Samsung 970 EVO Plus 500GB SSD + 232 GB SSD + 250 GB SSD portable drive + ISP = BT + Web Hosting = TSO Host

  3. #3
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Default Re: Dynamic Date Script

    Thanks Egg! You were right. Off to SpecSavers!

    Just one more thing. How do I align the text to the right of the placeholder?
    Thanks

    Steve
    Kettering UK

  4. #4
    Join Date
    Dec 2000
    Location
    Hautes Pyrénées, France
    Posts
    5,083

    Default Re: Dynamic Date Script

    it's a lot easier with php
    but your page must be called mypage.php and not mypage.html
    one simple command in the placeholder
    Code:
    <?php echo date("Y"); ?>
    all my sites are php so that i can take advantage of it
    my home page is called any_old_page.html which nothing links to and then the real home page people see is called index.php

    plus don't forget some people disable javascript or use the noscript plugin
    If someone tried to make me dig my own grave I would say No.
    They're going to kill me anyway and I'd love to die the way I lived:
    Avoiding Manual Labour.

  5. #5
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Default Re: Dynamic Date Script

    Thanks Frank. I'd prefer to use javascript.
    Thanks

    Steve
    Kettering UK

  6. #6
    Join Date
    Aug 2000
    Location
    Harwich, Essex, England
    Posts
    21,916

    Default Re: Dynamic Date Script

    The quickest way would be to move the placeholder to the right.
    Egg

    Intel i7 - 4790K Quad Core + 16 GB Ram + NVIDIA Geforce GTX 1660 Graphics Card + MSI Optix Mag321 Curv monitor
    + Samsung 970 EVO Plus 500GB SSD + 232 GB SSD + 250 GB SSD portable drive + ISP = BT + Web Hosting = TSO Host

  7. #7
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Default Re: Dynamic Date Script

    Hi Egg. Cheers, Yes, I can do that but as the date gets bigger/longer, it's currently defaulting to left aligned so the longer dates push the text off the right hand side of the page. If it were right aligned it would push the longer text to the left, where I've got plenty of room
    Thanks

    Steve
    Kettering UK

  8. #8
    Join Date
    Aug 2000
    Location
    Harwich, Essex, England
    Posts
    21,916

    Default Re: Dynamic Date Script

    Try this
    Attached Files Attached Files
    Egg

    Intel i7 - 4790K Quad Core + 16 GB Ram + NVIDIA Geforce GTX 1660 Graphics Card + MSI Optix Mag321 Curv monitor
    + Samsung 970 EVO Plus 500GB SSD + 232 GB SSD + 250 GB SSD portable drive + ISP = BT + Web Hosting = TSO Host

  9. #9
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Default Re: Dynamic Date Script

    Hi Egg

    You're a star. Works a treat. Thank you soooo much!
    Thanks

    Steve
    Kettering UK

  10. #10
    Join Date
    May 2002
    Location
    Canada
    Posts
    3,339

    Default Re: Dynamic Date Script

    Quote Originally Posted by SteveP View Post
    Hi Egg

    You're a star. Works a treat. Thank you soooo much!
    He is an Egg, a wonderful Egg

 

 

Tags for this Thread

Bookmarks

Posting Permissions

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