---
sourceDocument: Yokohama-API-Referenz
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/de-DE/yokohama/api-reference

 Release :

    - yokohama

ft:locale :

    - de-DE

ft:publication_title :

    - Yokohama-API-Referenz

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Dauer wird berechnet

# Dauer wird berechnet {#ariaid-title1}

* Freigeben Version: Yokohama
* 
* Aktualisiert 30. Januar 2025
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 Minuten Lesedauer

Häufig müssen Sie Anwendern eine Möglichkeit geben, anzugeben, wann eine Aufgabe oder ein Prozess fällig ist. Mit der Skripteinbindung „DurationCalculator" können Sie das Fälligkeitsdatum entweder mit einer einfachen Dauer oder einer relativen Dauer berechnen.  
Normalerweise erfordert das Festlegen eines Fälligkeitsdatums, dass Sie die Arbeitszeit und nicht die Gesamtzeit berechnen. Bei der Bestimmung des Fälligkeitsdatums wird nur der Teil des Tages berücksichtigt, an dem die Arbeit ausgeführt wird. Beispiel: Eine Aufgabe ist in 10 Stunden fällig, ist jedoch auf einen Geschäftstag-Zeitplan beschränkt. Wenn die Arbeit am Montag um 10:00 Uhr beginnt, ist sie am Dienstag um 12:00 Uhr fällig, wie unten berechnet.

    10am-5pm on Monday (6 hours) + 8am-12pm on Tuesday (4 hours)

Informationen zu Zeitplänen, die Sie als Eingaben für DurationCalculator-Methoden verwenden können, finden Sie unter [Zeitpläne werden erstellt und verwendet](https://www.servicenow.com/docs/access?context=c_UseSchedules&version=yokohama&pubname=yokohama-platform-administration&ft:locale=en-US).

Dieses Skript demonstriert, wie Sie den DurationCalculator zum Berechnen eines Fälligkeitsdatums verwenden.  

    /**
    * Demonstrate the use of DurationCalculator to compute a due date.
    *
    * You must have a start date and a duration. Then you can compute a
    * due date using the constraints of a schedule.
    */
     
    gs.include('DurationCalculator');
    executeSample();
     
    /**
    * Function to house the sample script.
    */function executeSample(){
     
        // First we need a DurationCalculator object.var dc =new DurationCalculator();
     
        // --------------- No schedule examples ------------------
     
        // Simple computation of a due date without using a schedule. Seconds// are added to the start date continuously to get to a due date.
        dc.setStartDateTime("5/1/2012");if(!dc.calcDuration(2*24*3600)){// 2 days
        	gs.log("*** Error calculating duration");return;}
        gs.log("calcDuration no schedule: "+ dc.getEndDateTime());// "2012-05-03 00:00:00" two days later
     
        // Start in the middle of the night (2:00 am) and compute a due date 1 hour in the future// Without a schedule this yields 3:00 am.
        dc.setStartDateTime("5/3/2012 02:00:00");if(!dc.calcDuration(3600)){
            gs.log("*** Error calculating duration");return;}
        gs.log("Middle of night + 1 hour (no schedule): "+ dc.getEndDateTime());// No scheduled start date, just add 1 hour
     
     
        // -------------- Add a schedule to the date calculator ---------------------
        addSchedule(dc);
     
        // Start in the middle of the night and compute a due date 1 hour in the future.// Since we start at 2:00 am the computation adds the 1 hour from the start// of the day, 8:00am to get to 9:00am
        dc.setStartDateTime("5/3/2012 02:00:00");if(!dc.calcDuration(3600)){//
            gs.log("*** Error calculating duration");return;}
        gs.log("Middle of night + 1 hour (with 8-5 schedule): "+ dc.getEndDateTime());// 9:00 am
     
        // Start in the afternoon and add hours beyond quiting time. Our schedule says the work day// ends at 5:00pm, if the duration extends beyond that, we roll over to the next work day.// In this example we are adding 4 hours to 3:00pm which gives us 10:00 am the next day.
        dc.setStartDateTime("5/3/2012 15:00:00");if(!dc.calcDuration(4*3600)){//
            gs.log("*** Error calculating duration");return;}
        gs.log("Afternoon + 4 hour (with 8-5 schedule): "+ dc.getEndDateTime());// 10:00 am.
     
        // This is a demo of adding 2 hours repeatedly and examine the result. This// is a good way to visualize the result of a due date calculation.
        dc.setStartDateTime("5/3/2012 15:00:00");// for(var i=2; i<24; i+=1){if(!dc.calcDuration(i*3600)){//
                gs.log("*** Error calculating duration");return;}
            gs.log("add "+ i +" hours gives due date: "+ dc.getEndDateTime());}
     
        // Setting the timezone causes the schedule to be interpreted in the specified timezone.// Run the same code as above with different timezone. Note that the 8 to 5 workday is// offset by the two hours as specified in our timezone.
        dc.setTimeZone("GMT-2");
        dc.setStartDateTime("5/3/2012 15:00:00");for(var i=2; i<24; i+=1){if(!dc.calcDuration(i*3600)){//
                gs.log("*** Error calculating duration");return;}
            gs.log("add "+ i +" hours gives due date (GMT-2): "+ dc.getEndDateTime());}}
     
    /**
    * Add a specific schedule to the DurationCalculator object.
    *
    * @param durationCalculator An instance of DurationCalculator
    */function addSchedule(durationCalculator){// Load the "8-5 weekdays excluding holidays" schedule into our duration calculator.var scheduleName ="8-5 weekdays excluding holidays";var grSched =new GlideRecord('cmn_schedule');
        grSched.addQuery('name', scheduleName);
        grSched.query();if(!grSched.next()){
            gs.log('*** Could not find schedule "'+ scheduleName +'"');return;}
        durationCalculator.setSchedule(grSched.getUniqueValue(),"GMT");}

* **[Einfache Dauer vs. Relative Dauer](https://servicenow-prod.fluidtopics.net/OauPDAO7SjAZa8LUFT8y9w#c_SImpleDurationVsRelativeDuration)**   
  Wie viel Arbeit zum Abschließen einer Aufgabe erforderlich ist, kann als „relative Dauer" ausgedrückt werden.
* **[Implementierung einer relativen Dauer](https://servicenow-prod.fluidtopics.net/GKfJiXfPMtQ0TjHS0Gx0vQ#t_HowToImplementARelativeDuration)**   
  Sie können eine relative Dauer implementieren, indem Sie die Tabelle „cmn_relative_duration" und erstellen Dauerrechner Skripteinbindung.

