ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage syntax / WLanguage types
  • Duration values
  • Duration properties
  • Supported values
  • Displaying a duration in an Edit control
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
The Duration type is used to easily manipulate intervals of dates and times. The Duration type can be used to perform calculations (subtraction, addition, etc.). For more details, see Operations available with the Duration type.
Remarks:
  • Several properties can be used with the Duration type, to retrieve the number of days or minutes, for example.
  • To assign a duration from the result of a function, use StringToDuration.
  • For more details on the declaration of this type of variable and the use of WLanguage properties, see Declaring a variable.
The Duration type supports null values. For more details, see Allowing nullable types.
Example
StartTime is Time = "1330"
EndTime is Time = "1730"
ConferenceDuration is Duration = EndTime - StartTime
TaskDuration is Duration = 3 Min 30s
Syntax
<Variable name> is Duration = <Value>
OR

<Variable name> is Duration
<Variable name> = <Value>
<Variable name>:
Name of the variable to declare. When several variables of the same type are declared and initialized on the same line, only the last variable is initialized.
<Value>:
In most cases, a duration is the result of an operation between the Date, Time and DateTime variables.
This value can correspond to:
  • a character string,
  • an integer (duration in milliseconds),
  • a duration (for example, another Duration variable),
  • the duration in a readable format (e.g.: 30 s).
0 is used to reset the duration.
Remarks

Duration values

If a Duration variable is manipulated:
  • using a string, this string is in the following format: "+DHHMMSSCCC" (days, hours, minutes, seconds, thousandths of a second).
  • using an integer, this integer corresponds to the duration in milliseconds.
  • using a duration, this duration can correspond to a Duration variable or to a clear description of the duration.
In most cases, a duration is the result of an operation between the Date, Time and DateTime variables. This value can be a duration.
0 is used to reset the duration.

Duration properties

The following properties can be used with durations:
InHoursReturns or modifies the number of hours corresponding to a duration. The number of hours is expressed as a real number.
InDaysReturns or modifies the number of days corresponding to a duration. The number of days is expressed as a real number.
InMillisecondsReturns or modifies the number of milliseconds corresponding to a duration. The number of milliseconds is expressed as an integer.
InMinutesReturns or modifies the number of minutes corresponding to a duration. The number of minutes is expressed as a real number.
InSecondsReturns or modifies the number of seconds corresponding to a duration. The number of seconds is expressed as a real number.
TimeReturns or modifies the number of hours. The number of hours is expressed as an integer.
DayReturns or modifies the number of days. The number of days is expressed as an integer.
MillisecondReturns or modifies the number of milliseconds. The number of milliseconds is expressed as an integer.
MinuteReturns or modifies the number of minutes. The number of minutes is expressed as an integer.
SecondReturns or modifies the number of seconds. The number of seconds is expressed as an integer.

For more details on the possible operations on durations (addition, subtraction, comparison), see Operations available with the Duration type.
StartTime is Time = "1330"
EndTime is Time = "1730"     
ConferenceDuration is Duration = EndTime - StartTime
Info("The conference lasted: " + ConferenceDuration.Hour + " hours")

Important: To store the values of the properties listed in the above table, you must respect the type of variable returned by each property. For example:
MyDuration is Duration
HowManyHours is real
 
MyDuration.Day = 5
HowManyHours = MyDuration.InHours
 
Info(MyDuration.Day + " days = " + HowManyHours + " hours")

In this example, the HowManyHours variable must be declared as a real (and not as an integer). If this variable is declared as an integer, its value will be an approximate number.

Supported values

The Duration type supports durations ranging from -2 billion days to 2 billion days. The precision is up to the millisecond.

Displaying a duration in an Edit control

To display a duration in an Edit control, you can use the DisplayMask property. For more details, see Display mask for durations.
Related Examples:
Calculations on durations Unit examples (WINDEV): Calculations on durations
[ + ] Calculations on dates and times with the WLanguage functions:
- Calculate the duration between two moments (dates and times)
- Calculate a sum of durations
- Calculate an average of durations
Minimum version required
  • Version 9
This page is also available for…
Comments
Contador Regressivo
Global
gduTempoMaximo is Duration = 5min

---
Thread in Procedure
Infinito e inicio automaico em um segundo
---

gduTempoMaximo..Second -= 1

STC_TempoRestante = NumToString(gduTempoMaximo..Hour,"02d") + ":" + NumToString(gduTempoMaximo..Minute,"02d") + ":" + NumToString(gduTempoMaximo..Second,"02d")

----
Tempo Restante: 00:04:55

BOLLER
10 Sep. 2019
Displaying a duration in Table column

DateTimeLOGIN = Table.MyLOGIN
DateTimeLOGOUT = Table.MyLOGOUT
MyDuration = DateTimeDifference(DateTimeLOGIN,DateTimeLOGOUT)+"0"
Table.MyDuration = MyDuration

Adding the "0" to the result of the calculation is necessary to get a correct display!

Guenter
29 May 2018
Duration..Hour help page documentation error
The Hour property of the Duration has been incorrectly labelled as "...Time". It should read "..Hour"
John
09 Dec. 2014

Last update: 03/28/2024

Send a report | Local help