How to add an automatic date-tracker to my site

Discussion in 'Web Design and Development' started by macaddict23, Apr 26, 2007.

  1. macrumors 6502

    macaddict23

    Joined:
    Jun 20, 2006
    Location:
    MacVille, USA
    #1
    I simply want to add the day's current date at the top of my site.
     
  2. macrumors 65816

    Nicolasdec

    Joined:
    Dec 7, 2006
    Location:
    São Paulo
    #2
    This could work

    PHP:
    <?php
    $nextWeek 
    time() + (24 60 60);
                       
    // 7 days; 24 hours; 60 mins; 60secs
    echo 'Now:       'date('Y-m-d') ."\n";
    echo 
    'Next Week: 'date('Y-m-d'$nextWeek) ."\n";
    // or using strtotime():
    echo 'Next Week: 'date('Y-m-d'strtotime('+1 week')) ."\n";
    ?>
     
  3. thread starter macrumors 6502

    macaddict23

    Joined:
    Jun 20, 2006
    Location:
    MacVille, USA
    #3
    Nicolasdec. Where do I insert this in source code?
     
  4. Moderator emeritus

    EricNau

    Joined:
    Apr 27, 2005
    Location:
    San Francisco, CA
    #4
    This should also work:
    Code:
    <script>
    var mydate=new Date() 
    var year=mydate.getYear() 
    if (year < 1000) year+=1900 
    var day=mydate.getDay() 
    var month=mydate.getMonth() 
    var daym=mydate.getDate() 
    if (daym<10) daym="0"+daym 
    var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday") 
    var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December") 
    document.write(""+montharray[month]+" "+daym+", "+year+"") 
    </script>
    Is it a simple html website? ...You just insert the code where you want the date to appear.
     
  5. thread starter macrumors 6502

    macaddict23

    Joined:
    Jun 20, 2006
    Location:
    MacVille, USA
    #5
    Yes, it's a simple HTML site.

    So like this:

    <code>
    <html>
    <head>
    <title>Today's Journal</title>
    </head>
    <body>
    <script>
    var mydate=new Date()
    var year=mydate.getYear()
    if (year < 1000) year+=1900
    var day=mydate.getDay()
    var month=mydate.getMonth()
    var daym=mydate.getDate()
    if (daym<10) daym="0"+daym
    var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
    var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
    document.write(""+montharray[month]+" "+daym+", "+year+"")
    </script>

    <p> Lorem ipsum . . . . </p>
    </body>
    </html>
    </code>
     
  6. Moderator emeritus

    EricNau

    Joined:
    Apr 27, 2005
    Location:
    San Francisco, CA
    #6
    Yes, exactly. You can also place it in a table, center it with <center> tags, etc. etc.
     
  7. macrumors G5

    CanadaRAM

    Joined:
    Oct 11, 2004
    Location:
    On the Left Coast - Victoria BC Canada
    #7
    <How to add an automatic date-tracker to my site>

    But remember, before your evening ends, you have to slip the GPS transponder into your date's pocket or handbag. Remember to turn it on, or else the link to Google Maps won't work...
     
  8. macrumors 65816

    Nicolasdec

    Joined:
    Dec 7, 2006
    Location:
    São Paulo
    #8
    Its a PHP script put it were you want.
     

Share This Page