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 4 of 4

Thread: get month

  1. #1
    New Coder hedbanger's Avatar
    Join Date
    Jun 2002
    Location
    vallejo, ca
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question get month

    my script is getting the wrong month. it should be july. what am i doing wrong? thanks.

    Code:
    <script language="JavaScript">
    now = new Date();
    month = now.getMonth();
    date = now.getDate();
    year = now.getYear();
    document.write("<font face='arial' size='1' color='#999999'><b>");
    document.write("LAST MODIFIED ON ");
    document.write("</b></font>");
    document.write("<font face='arial' size='1' color='#999999'><b>");
    document.write(month + "/" + date + "/" + year);
    document.write("</b></font>");
    </script>
    jf~ if you're not part of the solution, you're part of the precipitate.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    The months it returns are I believe from 0-11, not 1-12...

    var date = new Date();
    var dateString = date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear().toString().substr(2);

    That generates the date string you want...

  • #3
    New Coder hedbanger's Avatar
    Join Date
    Jun 2002
    Location
    vallejo, ca
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i know that the months are 0 through 11 but i wonder what i was doing that would cause it to not increment it correctly.
    oh well!
    what you gave me works, thanks!
    (good luck getting a summer job.)

    corrected script:
    <script language="JavaScript">
    var date = new Date();
    var dateString = date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear().toString().substr(2);
    document.write("<font face='arial' size='1' color='#999999'><b>");
    document.write("LAST MODIFIED ON ");
    document.write("</b></font>");
    document.write("<font face='arial' size='1' color='#999999'><b>");
    document.write(dateString);
    document.write("</b></font>");
    </script>
    jf~ if you're not part of the solution, you're part of the precipitate.

  • #4
    New Coder hedbanger's Avatar
    Join Date
    Jun 2002
    Location
    vallejo, ca
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh! i just noticed that you had to increment the month yourself too!
    jf~ if you're not part of the solution, you're part of the precipitate.


  •  

    Posting Permissions

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