Ankündigung

Einklappen
Keine Ankündigung bisher.

Different between to dates with Javascript not working correctly

Einklappen
X

Different between to dates with Javascript not working correctly

Einklappen
  • Filter
  • Zeit
Alles löschen
neue Beiträge

  • Different between to dates with Javascript not working correctly

    Hello All

    I have this function in Intrexx to calculate the difference between two dates;

    var nDate1 = getElement("0BDBDA370AF880243F3AB27722009934D03EC4 8B"); /*Datum datecontrol*/
    var nDate2 = getElement("3CCDACBAE68B2A659E0BE4BFD6161C84BDDF96 E0"); /*Abschluss am datecontrol*/
    var nDiff = getElement("A26A1279B454CB005D423DC22A3FB8BFE74EE4 B0"); /*Dauer (in Tagen) textcontrol*/
    if(getDateObject(nDate1) && getDateObject(nDate2)){
    var date1=getDateObject(nDate1);
    var date2=getDateObject(nDate2);
    var diff= Math.abs(date1-date2);
    Browser.setValue(nDiff, (diff/(1000*60*60*24));
    }

    This code works great for the 1st 18 days (so 10.10 to 28.10 gives 18 but to the 29.10 it gives 19.04666666.)
    I have a workaround but I am wondering why this doesn't work

  • #2
    I guess this is because of the summertime/wintertime issue.

    Kommentar


    • #3
      Never even thought of that.. I am using parseInt() to get around it. Is there a better way?

      Kommentar


      • #4
        Well end of march you would have -0.046666 instead of +0.046666 so you would have a problem anyway.
        Maybe you can use UTC or substract the TimeZone-Offset from both dates before you calculate the difference between them.

        Code:
        date.getTime() //time in millis
        date.getTimezoneOffset() //offset for your timezone in minutes

        Kommentar

        Lädt...
        X