Hi
I need to calculate the number of hours between two dates.
Is this possible or do I have to bring it in from my datasource?
Kr George
Hi George,
You can use the the minus "-" operator that can subtract also date types.
For example:
= Date2 - Date1 // Difference in days= (Date2 - Date1) * 24 // Difference in hours= (Date2 - Date1) * 24 *60 // Difference in minutes= (Date2 - Date1) * 24 *60 * 60 // Difference in seconds= (Date2 - Date1) * 24 *60 * 60 * 1000 // Difference in milliseconds
If you want to truncate the result, you can do the following:
= (<<expression>>) \ 1
For example (current hour):
=((Variables.Now - Variables.Today) * 24) \ 1
I hope this helps.
regards,
Simon
Hi Simon
Thanks for the response.
So my assumption that a date - a date is a timespan is incorrect?
I was assuming that I would have to do something like =(Date1 - Date2).TotalHours
Thanks
George
Hi George
A date - a date is a timespan. You are totally right.
But, you found a known issue there. Regrettably the ".TotalHours" will not work in the current version.
As a workaround you can use the expression I explained before.