Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate minutes between two 24-hour time values 1

Status
Not open for further replies.

heseir

IS-IT--Management
Aug 15, 2005
5
NO
Hallo,

In VB6 i used this function:
Function TimeDiff(ByVal inTime As String, ByVal outTime As String)
Dim ainTime As Date, aoutTime As Date
Dim mElapsed As Long

ainTime = Format(Right("0" & inTime, 4), "@@:mad:@") ' right justify the inTime
aoutTime = Format(Right("0" & outTime, 4), "@@:mad:@") ' right justify the outTime

TimeDiff = DateDiff("n", ainTime, aoutTime) ' calculate number of minutes elapsed
End Function

I can not seem to find any similar function in C#.

Is there any genies out there who can magically transform this one into a C# function.

The format I get from my users are ex. "0735" (began at work), and I then need to calculate minutes passed since "0000" (midnight"). In VB6 I then called TimeDiff(0000, 0735), and got 455, which is minutes between the two times.

All help and pointers will be greatly appreaciated!

Best regards,
Eirik Hesthamar
Norway
 
double TimeDiff(string start, string end)
{

DateTime startTime = DateTime.Parse(DateTime.MinValue.ToShortDateString() + " " + int.Parse(start).ToString("00:00"));
DateTime endTime = DateTime.Parse(DateTime.MinValue.ToShortDateString() + " " + int.Parse(end).ToString("00:00"));

TimeSpan ts;
ts = endTime- startTime ;




return ts.TotalMinutes;


}
 
First class answere!! And the reply speed was beyond words!!!! Were you just sitting around waiting for my question ;-)

Thanks!!!!!!!!!!

Best regards,
Eirik Hesthamar
Norway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top