Date format DD/MM/YYYY

Discussion in 'Javascript' started by Yas, Apr 18, 2008.

  1. Yas

    Yas Guest

    Hello I've got the following Javascript for a web calendar popup that
    outputs the date in 4/24/2008 (m/d/yyyy).

    How can i modify it to output dd/mm/yyyy e.g. 24/04/2008. So all
    outputs are in this format. The system this runs on has the correct
    date format (not US) so I would like the JavaScript to also use that
    format.

    Many thanks

    The code
    ------------------------------------
    var OneDay = 86400000
    var OneMonth = (OneDay * 30)
    var CurrentDate = new Date()
    varCurrentMonth = ""
    varMonth = new Array(12)
    varMonth[1] = "January"
    varMonth[2] = "February"
    varMonth[3] = "March"
    varMonth[4] = "April"
    varMonth[5] = "May"
    varMonth[6] = "June"
    varMonth[7] = "July"
    varMonth[8] = "August"
    varMonth[9] = "September"
    varMonth[10] = "October"
    varMonth[11] = "November"
    varMonth[12] = "December"
    varActiveTBox = ""
    varTop = "100"
    varLeft = "100"

    function DatePicker(TheDate,e,top,left)
    {
    varActiveTBox = e
    varTop = top
    varLeft = left
    var RefDate = new Date(TheDate)
    varDays = RefDate.getTime() - (OneDay * (RefDate.getDate()-1))
    RefDate.setTime(varDays)
    varDays = RefDate.getTime() - (OneDay * (RefDate.getDay()))
    RefDate.setTime(varDays)
    var MnthDate = new Date(TheDate)
    varDays = RefDate.getTime() + (OneDay * 15)
    MnthDate.setTime(varDays)
    varCurrentMonth = varMonth[MnthDate.getMonth()+1] + " " +
    MnthDate.getYear()
    CurrentDate = TheDate
    ShowCalendar(RefDate);
    }

    function Prev()
    {
    var pDate = new Date(CurrentDate);
    varpDays = pDate.getTime() - OneMonth;
    pDate.setTime(varpDays);
    DatePicker(pDate,varActiveTBox,varTop,varLeft);
    }

    function Next()
    {
    var nDate = new Date(CurrentDate);
    varnDays = nDate.getTime() + OneMonth;
    nDate.setTime(varnDays);
    DatePicker(nDate,varActiveTBox,varTop,varLeft);
    }

    function ShowCalendar(theDate){
    calendar.innerHTML = "";
    var DateLoop = new Date(theDate);

    var varCal ="<table border='0' cellspacing='2' cellpadding='1'
    class='calendar' style='left: " + varLeft + "px; TOP: " + varTop +
    "px'>";
    varCal += "<tr><td onClick=Prev() class='clicker'><</td>";
    varCal += "<td colspan='5' align='center' class='calheader'>" +
    varCurrentMonth +"</td>";
    varCal += "<td onClick=Next() class='clicker'>></td></tr>";

    for ( var r = 1; r <= 6; r++ ) {
    varCal += "<tr>"

    for ( var c = 1; c <= 7; c++ ) {
    varCal += "<td align='right' onClick=ShowDate('"
    varCal += DateLoop.getMonth()+1 + "/" + DateLoop.getDate() +
    "/" +
    DateLoop.getYear()
    varCal += "') class='calday'>" + DateLoop.getDate() + "</td>";
    varDays = DateLoop.getTime() + OneDay;
    DateLoop.setTime(varDays);


    }
    varCal += "</tr>"
    }
    varCal += "</table>"
    calendar.innerHTML = varCal
    }

    function ShowDate(theDate)
    {
    var myDate = new Date(theDate)

    calendar.innerHTML = ""
    varActiveTBox.value = theDate
    }
    Yas, Apr 18, 2008
    #1
    1. Advertising

  2. Yas

    Erwin Moller Guest

    Yas schreef:
    <snip>

    Hi Yas,

    We all saw your posting from 3 hours ago just fine.
    No need to repost the same question so fast.

    If you are lucky somebody fixes your code.
    I will not fix it because it is so basic.
    You should be able to do it yourself, which you didn't try.
    (At least you didn't show us anything.)

    I don't want to be rude, or lecture you, but....
    In general, just asking to fix your problem in a newgroup doesn't result
    in a solution/many responses.
    People think you are lazy, and should do it yourself.
    (We get paid most of the time to fix other peoples problems, you know..)

    However, if you ask something after trying yourself, AND show us what
    you tried, you might get much better responses.

    (Just a freindly word of advise.)

    Regards,
    Erwin Moller
    Erwin Moller, Apr 18, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q3liZXJMb3R1cw==?=

    Does CompareValidator work for the date in dd-mmm-yyyy format?

    =?Utf-8?B?Q3liZXJMb3R1cw==?=, Jun 10, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    15,809
    Peter Blum
    Jun 10, 2005
  2. Chu
    Replies:
    3
    Views:
    4,185
    Shawn
    Aug 15, 2006
  3. Ashraf Ansari

    convert MM/dd/yyyy format into dd/MM/yyyy

    Ashraf Ansari, Aug 30, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    790
    Alexey Smirnov
    Aug 30, 2007
  4. Gilles Ganault

    Converting DD MM YYYY into YYYY-MM-DD?

    Gilles Ganault, Aug 17, 2009, in forum: Python
    Replies:
    18
    Views:
    1,348
    Mark Tolonen
    Aug 20, 2009
  5. J P Singh
    Replies:
    4
    Views:
    281
    J P Singh
    Feb 10, 2004
Loading...

Share This Page