www.webdeveloper.com
Results 1 to 3 of 3

Thread: having trouble getting a date

  1. #1
    Join Date
    Jul 2010
    Posts
    106

    having trouble getting a date

    Someone tell me where I'm going wrong. I'm trying to print out the month/year ?

    Code:
    <html><head>
    <SCRIPT language=JavaScript>
    var dateNow = new Date();
    var monthNow = dateNow.getMonth();
    var yearNow = dateNow.getYear();
    function MakeArray(n) {
    this.length = n
    return this
    } 
    monthNames = new MakeArray(12)
    monthNames[1] = "Janurary"
    monthNames[2] = "February"
    monthNames[3] = "March"
    monthNames[4] = "April"
    monthNames[5] = "May"
    monthNames[6] = "June"
    monthNames[7] = "July"
    monthNames[8] = "August"
    monthNames[9] = "Sept."
    monthNames[10] = "Oct."
    monthNames[11] = "Nov."
    monthNames[12] = "Dec."
    function customDate(oneDate) {
    var theMonth = monthNames[oneDate.getMonth() +1]
    }
    </SCRIPT>
    </head><body><script type="text/javascript">
    document.write(theMonth + "/" + yearNow);
    </script>
    </body></html>

  2. #2
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    Your var is a local and you can not access it from the global scope, plus the function is not being called.

    You should also use fullyear.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint] | twitter | linkedin | http://www.pascarello.com

  3. #3
    Join Date
    Jul 2010
    Posts
    106
    got it. thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles