Forum Discussion
Time difference in hours
Hi,
I'm trying to calculate the diiference in hours between two date/time columns. When I use DateDiff I am not able to use the two columns below.
13 Replies
- SeanCommunity Champion
android1 So you've verified both columns are date/time.
Then maybe you have some start (FROM) times that are after the corresponding end (TO) times.
See if this works - but don't forget that this means some of your data is not in the right order...
Hours = SWITCH( TRUE(), 'Table'[TimeFrom]<'Table'[TimeTo], DATEDIFF('Table'[TimeFrom], 'Table'[TimeTo], HOUR), 'Table'[TimeFrom]>'Table'[TimeTo], DATEDIFF('Table'[TimeTo], 'Table'[TimeFrom], HOUR), 0 )- abodqmmRegular Visitor
Dear Sean i tried this method and it worked fine i want to see it in minutes how can i do it ?????
- VvelardeCommunity Champion
DATEDIFF(TablaHoras[TimeFrom];TablaHoras[TimeTo];HOUR)
- AnonymousNot applicable
Also can use a measure, i feel little faster loading time with this
TimeDiff = CONVERT(SELECTEDVALUE(Table[Date1],0)-SELECTEDVALUE(Table[Date2],0),DATETIME)
and then change the format to time hh:mm:ss
Cheers