PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Calculates the difference between two dates and times.
Note: To display the result of this function in a Duration variable, use StringToDuration.
Versions 16 and later
Universal Windows 10 App This function is now available for the Windows Phone applications.
New in version 16
Universal Windows 10 App This function is now available for the Windows Phone applications.
Universal Windows 10 App This function is now available for the Windows Phone applications.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 18 and later
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
New in version 18
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Example
// Time passed since 01/01/1998 at 12:15
Diff is string
Diff = DateTimeDifference("199801011215", DateSys() + TimeSys())
// Display the time passed
Info("Time passed: " + CR + ...
Left(Diff, 8) + "days" + CR + ...
Middle(Diff, 9, 2) + "hours" + CR + ...
Middle(Diff, 11, 2) + "minutes" + CR + ...
Middle(Diff, 13, 2) + "seconds" + CR + ...
Middle(Diff, 15, 2) + "hundredths of a second")
// Time passed since 01/01/1998 at 12:15
Diff is string
Diff = DateTimeDifference("199801011215", SysDateTime())
// Display the time passed
Info("Time passed: " + CR + ...
Left(Diff, 8) + "days" + CR + ...
Middle(Diff, 9, 2) + "hours" + CR + ...
Middle(Diff, 11, 2) + "minutes" + CR + ...
Middle(Diff, 13, 2) + "seconds" + CR + ...
Middle(Diff, 15, 2) + "hundredths of a second")
// To fill a duration from the result of DateTimeDifference
Diff is string = DateTimeDifference("199801011215", DateSys() + TimeSys())
// convert the difference into a duration variable
Duration1 is Duration = StringToDuration(Diff, durationCenti)

// --------------------------------------------
// Other possible solution
// DateTime1 is DateTime = "199801011215"
// DateTime2 is DateTime = SysDate() + SysTime()
// Duration1 is Duration = DateTime2 - DateTime1
// ----------------------------------------------

// Display the time passed
Info("Time passed: " + Duration1..Day + "days" + CR + ...
Duration1..Hour + "hours" + CR + ...
Duration1..Minute + "minutes" + CR + ...
Duration1..Second + "seconds" + CR + ...
Duration1..Millisecond + "thousandths of a second")
// To fill a duration from the result of DateTimeDifference
Diff is string = DateTimeDifference("199801011215", SysDateTime())
// convert the difference into a duration variable
Duration1 is Duration = StringToDuration(Diff, durationCenti)

// --------------------------------------------
// Other possible solution
// DateTime1 is DateTime = "199801011215"
// DateTime2 is DateTime = DateTimeSys()
// Duration1 is Duration = DateTime2 - DateTime1
// ----------------------------------------------

// Display the time passed
Info("Time passed: " + Duration1..Day + "days" + CR + ...
Duration1..Hour + "hours" + CR + ...
Duration1..Minute + "minutes" + CR + ...
Duration1..Second + "seconds" + CR + ...
Duration1..Millisecond + "thousandths of a second")
Syntax
<Result> = DateTimeDifference(<Start Date/Time> , <End Date/Time>)
<Result>: Character string
Numbers of days, hours, minutes, seconds passed between two dates in +/-DDDDDDHHMMSSCC format where:
  • DDDDDD is the number of days passed between the two specified "Date - Time",
  • HH is the number of hours,
  • MM is the number of minutes,
  • SS is the number of seconds,
  • CC is the number of hundredths of a second.
This result comes from the following operation: <End Date/Time> - <Start Date/Time>.
The result is negative if <Start Date/Time> is after <End Date/Time>.
Caution: To assign this result to a Duration variable, you must use StringToDuration associated with the durationCenti constant.
<Start Date/Time>: Character string or DateTime variable
Start date/time in the following format:
  • YYYYMMDDHHMMSSCC
  • YYYYMMDDHHMMSS
  • YYYYMMDDHHMM
  • YYYYMMDDHH
<End Date/Time>: Character string or DateTime variable
End date/time in the following format:
  • YYYYMMDDHHMMSSCC
  • YYYYMMDDHHMMSS
  • YYYYMMDDHHMM
  • YYYYMMDDHH
Remarks
The validity of dates and times passed in parameter is checked. A message is displayed if the date or time is invalid. A "Date - Time" is considered as being invalid if:
  • The date is invalid. The date validity can be checked by DateValid.
  • The time is invalid. The time validity can be checked by TimeValid.
This function cannot be used to calculate the number of days between dates before October 14 1582 (the switch from the Julian calendar to the Gregorian calendar will not be taken into account).
The storage format allows you to store dates from 01/01/0001 to 12/31/9999.
The calculations performed on dates by the WLanguage functions or by the WLanguage properties are accurate from January 1st 1583.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230std.dll
Windows Mobile wp230std.dll
WEBDEV - Browser code WDJS.DLL
Java wd230java.jar
Linux wd230std.so
Android wd230android.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
Display the result of DateTimeDifference

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
May 29 2018
Example
// Time passed since 01/01/1998 at 12:15
sTDatahoraAgenda is string = Middle(StringToDate(EDT_DataAgendamento)+StringToTime(Middle(EDT_DataAgendamento,12,5)),1,12) //"199801011215"
Diff is string
Diff = DateTimeDifference(sTDatahoraAgenda, DateSys() + TimeSys())
//Display the time passed
//Info("Time passed: " + CR + ...
//Left(Diff, 8) + "days" + CR + ...
//Middle(Diff, 9, 2) + "hours" + CR + ...
//Middle(Diff, 11, 2) + "minutes" + CR + ...
//Middle(Diff, 13, 2) + "seconds" + CR + ...
//Middle(Diff, 15, 2) + "hundredths of a second")

//Valida data
nSMinutos is int = Val(Middle(Diff, 11, 2))
IF CBOX_Agendamento..Value = True AND Middle(Diff, 11, 2) < 30
Info("A data e hora agendada tem que ser maior do que 30 minutos")
ok1 = False
ELSE
ok1 = True
END
adrianoboller
Nov. 27 2015