Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

datetime difference as decimal number

HI all, I need a column to calculate datetime difference between two datetime columns, enddate - startdate. 

Both columns are in this format 

7/19/2018 8:31:00 AM

I will add conditional columns which will have as condition the result of this datetime difference compared to 0 (>= or <0 )

So I need the result of the differecen to be expressed in (parts of) hours (or minutes) and also be able to show negative results (start date can be bigger than end date) but when datetimes are very close,  I get 0 instead so my conditional columns i create later are not correct. 

 

So I need your help please, how can I create a new column for  a difference between 2 datetime columns expressed as decimal number which allows also negative values?  

 

Thanks! 

1 ACCEPTED SOLUTION
Kristjan76
Responsive Resident
Responsive Resident

Hi there,

I think DATEDIFF can handle negative numbers now, DATEDIFF(startdate, enddata, HOUR) should work.
date.PNG


The other way of doing this would be to calculate:
(enddate - startdate) * 24 for hour,
(enddate - startdate) * (24 * 60) for minutes,
(enddate - startdate) * (24 * 60 * 60) for seconds.

 

Best regards,

Kristjan

 

View solution in original post

2 REPLIES 2
v-cherch-msft
Employee
Employee

Hi @Anonymous

 

Could you tell me if your problem has been solved? If it is,kindly mark the helpful answer as a solution if you feel that makes sense.If not, please share more details about your issue so that we could help further on it.

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Kristjan76
Responsive Resident
Responsive Resident

Hi there,

I think DATEDIFF can handle negative numbers now, DATEDIFF(startdate, enddata, HOUR) should work.
date.PNG


The other way of doing this would be to calculate:
(enddate - startdate) * 24 for hour,
(enddate - startdate) * (24 * 60) for minutes,
(enddate - startdate) * (24 * 60 * 60) for seconds.

 

Best regards,

Kristjan

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.