SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot lightwithoutheat's Avatar
    Join Date
    Feb 2002
    Location
    Washington DC
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date stamp troubles

    I'm using a simple JavaScript for a datestamp on my site. However, I'm getting an error when I go to validate it although it works just fine. I can't seem to figure out how to fix the problem so it validates correctly. Any help would be more than appreciated.

    The script is:
    <script language="JavaScript" type="text/javascript">
    // Get today's current date.
    var now = new Date();

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

    // Array list of months.
    var months = new Array('January','February','March','April','May','June','July','August','September','October','November','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("" + today + "");
    </script>

    If you need to view the error go to:
    http://validator.w3.org/check?uri=ht...doctype=Inline

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try putting () around the now.getDate().

    () automatically evals... but if this still doesn't work try eval(now.getDate)<10.

    at the very WORST you might need eval((now.geDate)<10) which should eval to 1 or 0.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Zealot lightwithoutheat's Avatar
    Join Date
    Feb 2002
    Location
    Washington DC
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    still having problems...

    Well, I'm still having problems with the script. The error reads:

    Line 93, column 26:
    var date = ((now.getDate()<10) ? "0" : "")+ (now.getDate());
    ^Error: character "<" is the first character of a delimiter but occurred as data

    and...

    Line 97, column 16:
    return (number < 1000) ? number + 1900 : number;
    ^Error: character "<" is the first character of a delimiter but occurred as data


    I'm not sure what that means, since I'm not knowledgeable with JavaScript. Any help on what that means and how I can correct it would be greatly appreciated. Thanks much.

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looking in the wrong place

    If you try just:

    Code:
    <script language=Javascript>
    
    var now=new Date();
    
    var date = ((now.getDate()<10) ? "0" : "")+ (now.getDate());
    
    alert(date);
    
    </script>
    in a plain webpage... you *should* see it works.

    This indicates the problem is elsewhere

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


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
  •