1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Javascript date problem

Discussion in 'HTML & JavaScript' started by almir, Sep 8, 2008.

  1. almir

    almir Power Member

    Joined:
    Jul 11, 2008
    Messages:
    728
    Likes Received:
    229
    Hi !

    I have a problem with jacascript code that should show a date on my Clickbank thank you page. It does show the date, but its not accurate. It shows September 7, 108

    Today is September 8, and 108. was long time ago :D

    I don't know anything about javascript, so I would ask for some help about this.

    I looked at my thank you page code, and this is only I've found about date :

    Code:
    <SCRIPT language=JavaScript>
    <!--
    var lmod = new Date();
    var monthname;
    var lmonth = lmod.getMonth();
    if (lmonth == 0) monthname = "January";
    if (lmonth == 1) monthname = "February";
    if (lmonth == 2) monthname = "March";
    if (lmonth == 3) monthname = "April";
    if (lmonth == 4) monthname = "May";
    if (lmonth == 5) monthname = "June";
    if (lmonth == 6) monthname = "July";
    if (lmonth == 7) monthname = "August";
    if (lmonth == 8) monthname = "September";
    if (lmonth == 9) monthname = "October";
    if (lmonth == 10) monthname = "November";
    if (lmonth == 11) monthname = "December";
    var outstr = monthname + " " + lmod.getDate() + ", " + lmod.getYear();
    document.write(outstr);
    // -->
    </SCRIPT>
    What could cause the problem ?
     
  2. ty180sx

    ty180sx Jr. VIP Jr. VIP Premium Member

    Joined:
    Nov 29, 2007
    Messages:
    170
    Likes Received:
    183
    Location:
    The place i call home
    Home Page:
    try this, it is in this format
    Tuesday, September 09, 2008

    Code:
     <SCRIPT LANGUAGE="JavaScript">
    
    <!-- Begin
    
    // 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);
    
    //  End -->
                </script>
     
    • Thanks Thanks x 1
  3. almir

    almir Power Member

    Joined:
    Jul 11, 2008
    Messages:
    728
    Likes Received:
    229
    Great, it works

    Thanks