Results 1 to 6 of 6

Thread: Show date only...?

  1. #1
    Join Date
    Aug 2006
    Location
    The land of vikings
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Show date only...?

    Hey,

    I got this script on my website: http://www.dynamicdrive.com/dynamicindex6/clock2.htm I have the script that shows both time and date, but I want it to ONLY show date. Anyone know what to add/remove from the script to do this? Thanks!

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Code:
    <script type="text/javascript">
    var dt = new Date();
    var d  = dt.getDate();
    var day = (d < 10) ? '0' + d : d;
    var m = dt.getMonth() + 1;
    var month = (m < 10) ? '0' + m : m;
    var yy = dt.getYear();
    var year = (yy < 1000) ? yy + 1900 : yy;
    document.write(day + "-" + month + "-" + year);
    </script>
    If you want to show only the current date then the above code will do the job.

    I wonder why you are using a lengthy code just to show date

  3. #3
    Join Date
    Aug 2006
    Location
    The land of vikings
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks, but I need it to appear like: Tuesday, 31st October. I use that script because it loads fast, and shows the date how I want it, I just dont want the time. If anyone knows another script that shows the date like above, please link to it, that would be great.

  4. #4
    Join Date
    Apr 2006
    Location
    London
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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("<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+"</b></font></small>")
    
    </script>
    there you go.

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This should serve you:
    Code:
    <script type="text/javascript">
    var DAYS = [
      "Sunday",
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday"
    ],
      MONTHS = [
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December"
      ],
      SUFFIXES = {
        1 : "st",
        2 : "nd",
        3 : "rd",
        21 : "st",
        22 : "nd",
        23 : "rd", 
        31 : "st",
        'default' : "th"
      },
      d = new Date();
    
    document.write(DAYS[d.getDay()] + ", " + d.getDate() + (SUFFIXES[d.getDate()] || SUFFIXES['default']) + MONTHS[d.getMonth()]);
    </script>
    <small><font color='000000' face='Arial'><b>
    Ouch. Never use presentational HTML. Also, all colours in HTML notation must be prefixed with a hash sign (#).
    var year=mydate.getYear()
    if (year < 1000)
    year+=1900
    Instead, try .getFullYear().
    <script>
    The type attribute is required.
    Last edited by Twey; 10-31-2006 at 06:03 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Aug 2006
    Location
    The land of vikings
    Posts
    37
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks alot guys! I saved them all, so I can learn how its working.

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
  •