How can i get total number of hours between two datetime variable?
date1=1/1/2011 12:00:00
date2=1/3/2011 13:00:00
datetime date1 ;
datetime date2;
int hours=(date1.date2).hours;
the output is “1” but i want the total hour difference between two date i.e 49hours
thanks
Use
TotalHoursinstead ofHours. Note that the result is adouble– you can just cast it tointto get the whole number of hours. (Check what behaviour you want if the result is negative though…)From the docs for
Hours:You don’t want the hour component – you want the whole time span, expressed in hours.