Skip to main content Link Search Menu Expand Document (external link)

minutesBetween() : Calculate Minutes Between Dates


On this page

Summary

Calculate the number of minutes between two datetimes. Returns a positive or negative number depending on whether the second datetime is after or before the first.

Signature

minutesBetween(startDateTime, endDateTime)

Parameters

Parameter Type Required Description
startDateTime DateTime Yes The starting datetime
endDateTime DateTime Yes The ending datetime

Returns

Type: Number (Integer)

The number of minutes between the two datetimes. Positive if endDateTime is after startDateTime, negative if before.


Examples

Meeting Duration

<p>Meeting duration:  minutes</p>

Data:

doc.Params["model"] = new {
    startTime = new DateTime(2024, 3, 15, 14, 0, 0),
    endTime = new DateTime(2024, 3, 15, 15, 30, 0)
};

Output:

<p>Meeting duration: 90 minutes</p>

Parking Duration and Cost

<h3>Parking Receipt</h3>
<p>Entry: </p>
<p>Exit: </p>
<p>Duration:  minutes</p>
<p>Cost: $</p>

Data:

doc.Params["model"] = new {
    entryTime = new DateTime(2024, 3, 15, 10, 15, 0),
    exitTime = new DateTime(2024, 3, 15, 14, 45, 0),
    hourlyRate = 5.00
};

Output:

<h3>Parking Receipt</h3>
<p>Entry: 10:15 AM</p>
<p>Exit: 2:45 PM</p>
<p>Duration: 270 minutes</p>
<p>Cost: $22.5</p>

Call Center Metrics


  <p>Call :  min
  
    (Extended)
  
  </p>

<p>Average:  min</p>

Data:

doc.Params["model"] = new {
    calls = new[] {
        new {
            id = "001",
            startTime = new DateTime(2024, 3, 15, 9, 0, 0),
            endTime = new DateTime(2024, 3, 15, 9, 5, 30),
            duration = 5
        },
        new {
            id = "002",
            startTime = new DateTime(2024, 3, 15, 9, 10, 0),
            endTime = new DateTime(2024, 3, 15, 9, 25, 0),
            duration = 15
        }
    }
};

Output:

<p>Call 001: 5 min</p>
<p>Call 002: 15 min (Extended)</p>
<p>Average: 10 min</p>

Notes

  • Returns integer number of minutes (fractional minutes are truncated)
  • Positive result: endDateTime is after startDateTime
  • Negative result: endDateTime is before startDateTime
  • Includes both date and time components
  • For second-level precision, use secondsBetween()
  • For hour-level precision, use hoursBetween()
  • For fractional minutes, calculate using secondsBetween() / 60

See Also