Home Calculating how many minutes there are between two times
Reply: 0

Calculating how many minutes there are between two times

user1104
1#
user1104 Published in May 22, 2018, 4:34 am

I have a datagridview in my application which holds start and finish times. I want to calculate the number of minutes between these two times. So far I have got:

var varFinish = tsTable.Rows[intCellRow]["Finish Time"];
TimeSpan varTime = (DateTime)varFinish - (DateTime)varValue;
int intMinutes = TimeSpan.FromMinutes(varTime);

But the last line won't compile because it says I am using invalid arguments for the Timespan constructor. I've researched quite a bit about how to calculate the number of minutes between two times, but I'm hitting a bit of a brick wall. Can someone please advise me on the best way to achieve my objective.

EDIT/

Now my code is as follows:

var varFinish = tsTable.Rows[intCellRow]["Finish Time"];
TimeSpan varTime = (DateTime)varFinish - (DateTime)varValue;
int intMinutes = (int)varTime.TotalMinutes;

But I am getting an invalid cast on the second line. Both varFinish and varValue are times e.g. 10:00 and 8:00 say. So not sure why they won't cast to type DateTime?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.407093 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO