#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    39
    Rep Power
    2

    Post How to display date with javascript coding?


    Hi there,
    I am new on javascript section. Just have started to learn javascript. I am trying to coding to show date and day......
    here is the code I have created. It is showing only Wednesday when I am refreshing browser.
    Is there any wrong I have made? will you check please

    <html>
    <head><title>Date Select</title>
    </head>
    <body>
    <script type="text/javascript">
    var date=new Date();
    var day=date.getDay();
    if (day==0)
    {
    window.document.write("Sunday");
    }
    else if (day==1)
    {
    window.document.write("Monday");
    }
    else if (day==2)
    {
    window.document.write("Tuesday");
    }
    else if (day==3)
    {
    window.document.write("Wednesday");
    }
    else if (day==4)
    {
    window.document.write("Thursday");
    }
    else if (day==5)
    {
    window.document.write("Friday");
    }
    else if (day==6)
    {
    window.document.write("Saturday");
    }
    </script>
    </body>
    </html>

    I am waiting for your reply
    Thanks in advance
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,040
    Rep Power
    119
    What browser are you using; because I tested in IE, FF, and Chrome and they all show Tuesday?
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    39
    Rep Power
    2
    Originally Posted by web_loone08
    What browser are you using; because I tested in IE, FF, and Chrome and they all show Tuesday?
    I am using firefox 10.0.2 version and it is showing Wednesday.
  6. #4
  7. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,040
    Rep Power
    119
    Well I tested in the latest version of FF, which is 15.0.1 and it displays Tuesday. You might want to check the date on your computer and see if it is set to Wednesday. Unless you have some more JS somewhere, that would be changing the day variable; then I do not know what the explanation would be.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    153
    Rep Power
    5
    hi,

    I just checked using chrome, firefox 15.0.1 and IE8, and they all display Thursday.

    I like you am new to JavaScript, but i think this code is all good.

    As suggested above you may want to test the date on your computer.

    Regards
    MG

IMN logo majestic logo threadwatch logo seochat tools logo