0

Wird nicht berechnet der Januar 31 Tage

Liebe Comunity 

Ich habe diesen code bekommen wenn ich nich nicht teusche von Mirko, ( Hallo Mirko )

der ist super gut aber der berechnet mir den januar als 30 tage nicht 31 tage. 

 

Kann mann es korigieren ?

hier der code

Besten Dank im voraus

let DATUM1 := first('Data Dal');
let DATUM2 := first('Data Al');
if DATUM1 = null or DATUM2 = null then
    ""
else
    let D1 := if DATUM1 > DATUM2 then DATUM2 else DATUM1 end;
    let D2 := if DATUM1 > DATUM2 then DATUM1 else DATUM2 end;
    let DD := if day(D2) >= day(D1) then
            day(D2) - day(D1)
        else
            day(date(year(D1), month(D1) + 1, 1) - 1) - day(D1) + day(D2)
        end;
    let MM := if month(D1) <= month(D2) then
            month(D2) - month(D1)
        else
            12 - month(D1) + month(D2)
        end;
    let MMM := if day(D2) >= day(D1) then
            MM
        else
            if MM = 0 then 11 else MM - 1 end
        end;
    let YY := if month(D2) > month(D1) then
            year(D2) - year(D1)
        else
            if month(D2) < month(D1) then
                year(D2) - year(D1) - 1
            else
                if day(D1) <= day(D2) then
                    year(D2) - year(D1)
                else
                    year(D2) - year(D1) - 1
                end
            end
        end;
    if DATUM1 = null then
        ""
    else
        if YY = 0 then
            ""
        else
            if YY = 1 then
                YY + " Anno" + if MMM = 0 and DD = 0 then "" else ", " end
            else
                YY + " Anni" + if MMM = 0 and DD = 0 then "" else ", " end
            end
        end + if MMM = 0 then
            ""
        else
            if MMM = 1 then
                MMM + " Mese" + if DD = 0 then "" else ", " end
            else
                MMM + " Mesi" + if DD = 0 then "" else ", " end
            end
        end + if DD = 0 then
            ""
        else
            if DD = 1 then DD + " Giorno" else DD + " Giorni" end
        end
    end
end

3 Antworten

null
    • mirko3
    • vor 1 Jahr
    • Gemeldet - anzeigen

    Hi Alan, die Berechnung ist korrekt. Der erste Tag wird dabei nicht gezählt. Das Script beantwortet also sinngemäss die Frage: "Wie viele Tage sind es bis zum Enddatum?". Es sind vom 1.1. ab berechnet noch 30 Tage bis zum 31.1.

    Wenn Du nur die Tage zählen willst zwischen zwei Daten, dann hilft Dir vielleicht die Funktion days(). Und auch da mußt du einen Tag hinzuaddieren. Bsp.

    days(date(2022,1,1),date(2022,1,31)) = 30
    

    ...oder in Deinem Fall

    days(first('Data Dal'),first('Data Al'))
    

    P.S. Nur der Vollständigkeit und des Urheberrechts ;-) halber, das Datumscript stammt wahrscheinlich von Leo, dass zur Berechnung inklusive der Stunden und Minuten ist von mir.

      • alan_iselin
      • vor 1 Jahr
      • Gemeldet - anzeigen

      Mirko Hallo Mirko 

      Vielen Dank für deine zeit und Erklärung, Ich danke Dir und Leo gleichzeitig für die grossartige hilfe, 

      Schönen nachmitag wünsche ich noch

      Liebe Grüße 

      Alan

    • mirko3
    • vor 1 Jahr
    • Gemeldet - anzeigen

    ...oder einfach so:

    let DATUM1 := first('Data Dal');
    let DATUM2 := first('Data Al') + 1;
    if DATUM1 = null or DATUM2 = null then
        ""
    else
        let D1 := if DATUM1 > DATUM2 then DATUM2 else DATUM1 end;
        let D2 := if DATUM1 > DATUM2 then DATUM1 else DATUM2 end;
        let DD := if day(D2) >= day(D1) then
                day(D2) - day(D1)
            else
                day(date(year(D1), month(D1) + 1, 1) - 1) - day(D1) + day(D2)
            end;
        let MM := if month(D1) <= month(D2) then
                month(D2) - month(D1)
            else
                12 - month(D1) + month(D2)
            end;
        let MMM := if day(D2) >= day(D1) then
                MM
            else
                if MM = 0 then 11 else MM - 1 end
            end;
        let YY := if month(D2) > month(D1) then
                year(D2) - year(D1)
            else
                if month(D2) < month(D1) then
                    year(D2) - year(D1) - 1
                else
                    if day(D1) <= day(D2) then
                        year(D2) - year(D1)
                    else
                        year(D2) - year(D1) - 1
                    end
                end
            end;
        if DATUM1 = null then
            ""
        else
            if YY = 0 then
                ""
            else
                if YY = 1 then
                    YY + " Anno" + if MMM = 0 and DD = 0 then "" else ", " end
                else
                    YY + " Anni" + if MMM = 0 and DD = 0 then "" else ", " end
                end
            end + if MMM = 0 then
                ""
            else
                if MMM = 1 then
                    MMM + " Mese" + if DD = 0 then "" else ", " end
                else
                    MMM + " Mesi" + if DD = 0 then "" else ", " end
                end
            end + if DD = 0 then
                ""
            else
                if DD = 1 then DD + " Giorno" else DD + " Giorni" end
            end
        end
    end
    

Content aside

  • vor 1 JahrZuletzt aktiv
  • 3Antworten
  • 29Ansichten
  • 2 Folge bereits