Duration

Duration[expr]

returns the duration of expr.

Duration[expr,unit]

returns the result in the specified unit.

Details

  • Duration can be computed on a variety of objects and entities that have an associated length of time.
  • Some supported objects are:
  • Audio[samples]length of samples divided by sample rate
    DateInterval[{start,end}]duration between start and end
    DateObject[]duration given by the object's granularity
    Entity[]duration, based on start date, end date and more
    Sound[prims]computed from sound primitives prims
    Sound[prims,t]
    Sound[prims,{tmin,tmax}]
    SampledSoundList[{a1,,an},r]
    SampledSoundFunction[f,n,r]
    SoundNote[spec]
    SoundNote[spec,t]
    SoundNote[spec,{tmin,tmax}]
    TimeObject[]duration given by the object's granularity
    TimeSeries[]difference between last time and first time
    Video[]approximate duration of video, audio and subtitle tracks
  • By default, the unit of the result is automatically chosen to best represent the duration of expr. Use Duration[expr,unit] to specify a unit.
  • The unit specification unit can be any of the following:
  • Automaticautomatically determined unit
    unitany unit compatible with "Seconds"
    quantityany quantity with time units
    Noneduration in seconds returned as a real number

Examples

open allclose all

Basic Examples  (2)

Duration of an Audio object:

Duration of a DateInterval in years:

Scope  (10)

Input Data  (8)

Duration of a Sound object:

A sound from a sequence of notes:

A Video object:

A TimeSeries object:

Duration of a financial time series:

Duration of an Entity:

Duration of a DateObject:

The result depends on the granularity of the input:

Duration of a TimeObject:

The result depends on the granularity of the input:

Target Unit  (2)

By default, a reasonable unit is chosen for the result:

Specify a target unit:

Specify a target unit using a quantity:

Use None as the second argument to return the duration in seconds as a real number:

Applications  (1)

Get the Audio duration in seconds:

Represent the duration in minutes:

Properties & Relations  (4)

Duration automatically optimizes the unit of the result:

For Audio, dividing the number of samples by the sample rate is equivalent to the duration:

Audio duration can be computed by dividing the number of samples by the sample rate:

The duration of audio files can be imported directly from the file:

Compare with the duration of the imported audio:

Duration returns approximate duration for video files:

Compare with the "Duration" element in Import:

Get exact durations for all tracks using "ExactDurations" element:

Computing "Duration" is typically faster than computing "ExactDurations":

Wolfram Research (2016), Duration, Wolfram Language function, https://reference.wolfram.com/language/ref/Duration.html (updated 2023).

Text

Wolfram Research (2016), Duration, Wolfram Language function, https://reference.wolfram.com/language/ref/Duration.html (updated 2023).

CMS

Wolfram Language. 2016. "Duration." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/Duration.html.

APA

Wolfram Language. (2016). Duration. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Duration.html

BibTeX

@misc{reference.wolfram_2024_duration, author="Wolfram Research", title="{Duration}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/Duration.html}", note=[Accessed: 15-October-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_duration, organization={Wolfram Research}, title={Duration}, year={2023}, url={https://reference.wolfram.com/language/ref/Duration.html}, note=[Accessed: 15-October-2024 ]}