how do I know the difference between two DateTime?

how do I know the difference between two DateTime?

my space is two variables that receives 2 DateTime different, the starting and ending, I wanted to know how and what functions useful to get me a DateTime indicating the difference between these dates?

I'll send one more example I used does not work when I add the minutes or seconds .. only works when I only peopl time.

example that works only hours:


exemple return: 02:00:00

example that does not work and returns nothing:



exemple return: 00:00:00


Adilson Batista.
Hi Adilson,

If you need date time ( the two dates could have days of diference) the best solution is to separate all the components in difrent variables (ex: years; months; days;...
you can create a structure to store that info.

after that if you need to show the diference you simply show year+"-"+month+...

if you need to use this diference to add in other date time variable you just add them separatly addyear(newdate, year) addmonth (newdate,month)...

if you ned to get those values you do something like this

get the diference =DiffSeconds( datetime1, datetime2)  
secunds = mod (diference ,60)
diference = trunc(diference/60)
minutes = mod(diference,60)
diference = trunc(diference/60)
hours = mod(diference,24)
diference = trunc(diference/24)
or  you can add the diference to a null date, and when you need the values you use
month(date) - month(nulldate())

hope that this helped
Carlos Rocha

I also notice that your code isn't working because of this

newtime (hour,min sec)

if your diference is 2h you are doing something like that :

and what you should have is something like

thanks you, your help was of good intention and very help-me.

thanks you,
adilson batista.
I have found this way to do that. It worked for me.
    If( DiffMinutes(date time start,date time end) > 60,DiffHours(date time start,date time end),0) ,
Mod(DiffMinutes(date time start,date time end),60),0)
Below the refined way
NewTime(If( DiffMinutes(ConsultaTable.List.Current.Atendimento.dtHoraInicio,ConsultaTable.List.Current.Atendimento.dtHoraTermino) > 60,Trunc(DiffMinutes(ConsultaTable.List.Current.Atendimento.dtHoraInicio,ConsultaTable.List.Current.Atendimento.dtHoraTermino)/60),0) ,