Duration
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}] 
MusicScore[…] duration based on duration of events MusicVoice[…] duration based on duration of events MusicMeasure[…] duration based on duration of events MusicNote[…] duration assuming 120 beats per minute MusicChord[…] duration assuming 120 beats per minute MusicRest[…] duration assuming 120 beats per minute 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:
-
Automatic automatically determined unit unit any unit compatible with "Seconds" quantity any quantity with time units None duration in seconds returned as a real number
Examples
open all close allBasic Examples (2)
Duration of an Audio object:
Duration[\!\(\*AudioBox[""]\)]Duration of a DateInterval in years:
Duration[DateInterval[{DateObject[{2015, 2, 4}, "Day", "Gregorian", -5.], DateObject[{2019, 8, 15}, "Day", "Gregorian", -5.]}], "Years"]Scope (11)
Input Data (9)
Duration of a Sound object:
Duration[Sound[«1»]]A sound from a sequence of notes:
Duration[Sound[{SoundNote[0], SoundNote[1], SoundNote[2], SoundNote[3], SoundNote[4], SoundNote[5],
SoundNote[6], SoundNote[7], SoundNote[8], SoundNote[9], SoundNote[10], SoundNote[11],
SoundNote[12]}]]A MusicScore object:
Duration[MusicScore[<|"VoiceList" ->
{MusicVoice[<|"MeasureList" ->
{MusicMeasure[<|"NoteList" -> {MusicNote[<|"Pitch" -> MusicPitch[<|"Accidental" -> 0,
"Key" -> "G"|>], "Duration" -> MusicDuration[<|"BeatDuration" -> 1/4,
... BeatLength" -> 1|>]|>]},
"TimeSignature" -> MusicTimeSignature[<|"Numerator" -> 4, "Denominator" -> 4,
"BeatLength" -> 1|>]|>]}, "TimeSignature" ->
MusicTimeSignature[<|"Numerator" -> 4, "Denominator" -> 4, "BeatLength" -> 1|>]|>]]A Video object:
Duration[Video["ExampleData/Caminandes.mp4"]]A TimeSeries object:
ts = TimeSeries[{2, 1, 6, 5, 7, 4}, {{1, 2, 5, 10, 12, 15}}]Duration[ts]Duration of a financial time series:
ts = TimeSeries[FinancialData["MSFT", {"Jan. 1, 2010", "Sep. 1, 2010"}]]Duration[ts]Duration of an Entity:
Duration[Entity["HistoricalPeriod", "EuropeanRenaissance"]]Duration of a DateObject:
Duration[DateObject[{2022}]]The result depends on the granularity of the input:
Duration[DateObject[{2022, 8, 1}, "Week"]]Duration of a TimeObject:
Duration[TimeObject[]]The result depends on the granularity of the input:
Duration[TimeObject[{11, 30}, "Minute"]]Target Unit (2)
By default, a reasonable unit is chosen for the result:
Duration[DateInterval[{DateObject[{2015, 2, 4}, "Day", "Gregorian", -5.], DateObject[{2019, 8, 15}, "Day", "Gregorian", -5.]}]]Duration[DateInterval[{DateObject[{2015, 2, 4}, "Day", "Gregorian", -5.], DateObject[{2019, 8, 15}, "Day", "Gregorian", -5.]}], "Weeks"]Specify a target unit using a quantity:
Duration[DateInterval[{DateObject[{2015, 2, 4}, "Day", "Gregorian", -5.], DateObject[{2019, 8, 15}, "Day", "Gregorian", -5.]}], Quantity[1, "Seconds"]]Use None as the second argument to return the duration in seconds as a real number:
Duration[Audio@"ExampleData/rule30.wav", None]Applications (1)
Get the Audio duration in seconds:
a = ExampleData[{"Audio", "SubwayTrain"}];Duration[a]Represent the duration in minutes:
UnitConvert[%, "Minutes"]Properties & Relations (4)
Duration automatically optimizes the unit of the result:
Duration[AudioGenerator["Sin"]]Duration[Audio["http://exampledata.wolfram.com/bach.mp3"]]Duration[TimeSeries[FinancialData["GE", {"Jan/1/2010", "Feb/1/2010"}]]]For Audio, dividing the number of samples by the sample rate is equivalent to the duration:
a = AudioGenerator["Sin", 2.5]Audio duration can be computed by dividing the number of samples by the sample rate:
QuantityMagnitude@N[AudioLength[a] / AudioSampleRate[a]]The duration of audio files can be imported directly from the file:
Import["ExampleData/sample.flac", "Duration"]Compare with the duration of the imported audio:
Import["ExampleData/sample.flac"]//DurationDuration returns approximate duration for video files:
Duration[Video["ExampleData/Caminandes.mp4"]]Compare with the "Duration" element in Import:
Import["ExampleData/Caminandes.mp4", "Duration"]Get exact durations for all tracks using "ExactDurations" element:
Import["ExampleData/Caminandes.mp4", "ExactDurations"]Computing "Duration" is typically faster than computing "ExactDurations":
First[RepeatedTiming[Import["ExampleData/Caminandes.mp4", #]]]& /@ {"Duration", "ExactDurations"}See Also
AudioLength Length Dimensions TimeObject Audio Sound TimeSeries
Related Guides
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_2026_duration, author="Wolfram Research", title="{Duration}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/Duration.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_duration, organization={Wolfram Research}, title={Duration}, year={2023}, url={https://reference.wolfram.com/language/ref/Duration.html}, note=[Accessed: 13-June-2026]}