Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool Day (in date) with 2 digits

    Hi,

    How I write the following using a javascript?

    2008/10/02

    Thank you

    Lebron

  • #2
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I did the following, but not works!



    <SCRIPT LANGUAGE="JavaScript">



    <!-- Begin
    var months=new Array(13);
    months[1]="01";
    months[2]="02";
    months[3]="03";
    months[4]="04";
    months[5]="05";
    months[6]="06";
    months[7]="07";
    months[8]="08";
    months[9]="09";
    months[10]="10";
    months[11]="11";
    months[12]="12";
    var time=new Date();
    var lmonth=months[time.getMonth() + 1];
    var date=time.getDate();
    var year=time.getYear();
    if (year<100) year="19" + time.getYear();
    else year=time.getYear();
    document.write("<center>" + year + lmonth + " ");
    if (Date < 10)
    document.write(0 + date + ", " + "</center>");
    else
    document.write(date + ", " + "</center>");
    // End -->
    </SCRIPT>
    <!-- END OF SCRIPT -->



    Thanks

    Lebron

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <SCRIPT LANGUAGE="JavaScript">
    
    
    
    <!-- Begin
    function FormatNu(nu){
     return nu>9?nu:'0'+nu;
    }
    
    var time=new Date();
    var lmonth=time.getMonth() + 1;
    var date=time.getDate();
    var year=time.getFullYear();
    else year=time.getYear();
    document.write("<center>" + year +" "+ FormatNu(lmonth) + " ");
    document.write(FormatNu(date) + ", " + "</center>");
    // End -->
    </SCRIPT>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #4
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you.

    It gives an error message at:

    else year=time.getYear();
    Why?

    Lebron

  • #5
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    oops

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <SCRIPT LANGUAGE="JavaScript">
    
    
    
    <!-- Begin
    function FormatNu(nu){
     return nu>9?nu:'0'+nu;
    }
    
    var time=new Date();
    var lmonth=time.getMonth() + 1;
    var date=time.getDate();
    var year=time.getFullYear();
    document.write("<center>" + year +" "+ FormatNu(lmonth) + " ");
    document.write(FormatNu(date) + ", " + "</center>");
    // End -->
    </SCRIPT>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #6
    Regular Coder
    Join Date
    Oct 2006
    Location
    Spain
    Posts
    149
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Dear VWPhillips ,

    Thank you. The script it is working fine now, thanks to your help!

    Lebron


  •  

    Posting Permissions

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