Dear Sir,
I am encountering a problem and needs your support .The details of the issue is mentioned below :
Environment details - Database : SQL Server 2000 ; ERP Version : Microsoft GP 9.0, Visual studio-2005.
Problem Statement : How to calculate difference between two DateTime Picker controls( i.e User Entry) in terms of Hours and Minutes only.
Problem Statement : How to calculate difference between two DateTime Picker controls( i.e User Entry) in terms of Hours and Minutes only.
Problem Details:
1. We are having one C# .Net Modular Screen where there are several DateTime Picker Controls accepting Date and Time ( both) in terms of TimeTO and TimeFROM.
2. The difference of Date and Time(both) from the controls is being accepted by their Textbox respectively.
3, But, difference of DateTime Picker( i.e TimeTO and TimeFROM) gives " Day: Hour: Min: Sec. And , we want Difference in terms of Hours and Minutes only and all the difference will be finally added to get" Total Hours and Minutes".
4, We have used most of properties but not getting the same.
5. Please provide the .net C# code for window forms, for the same or any other solution.
With Regards,
Naveen Kumar
Graham Shorey42 pointsPosted Dec 12, 2006, 11:19 PM EST
TimeSpan ts = dateTimePicker1.Value - dateTimePicker2.Value;
naveen kumar7 pointsPosted Dec 13, 2006, 12:50 AM EST
TimeSpan ts = dateTimePicker1.Value - dateTimePicker2.Value;
But the difference , i am getting as for ts is " Day(s): Hours:Min:Sec" , in textbox.
What i want is to get the difference in terms of " Hours: Mins" only in textbox in the format i have written , whatsoever the user enters the date and time for each picker control..
How to do the same...
Then i want to add all the difference of DateTime Pickers ( in terms of Hour: Min only ) in another Textbox . how to do the same .
Graham Shorey42 pointsPosted Dec 13, 2006, 1:00 AM EST
If you can't do simple Math functions and update a textbox I'd suggest you read up on the basics of C# programming.
naveen kumar7 pointsPosted Dec 13, 2006, 1:28 AM EST
My Code is:
TimeSpan ts = new TimeSpan();
double s1;
double s2;
ts = dtp2.Value - dtp1.Value;
s1 = Convert.ToDouble(ts.TotalHours);
s2 = Convert.ToDouble(ts.TotalMinutes);
txt1.Text = String.Format("{0}:{1}", s1, s2);
But, i am getting the hours in correct format but minutes not in the correct format i.e some junk no.s..
How to rectify it....
Graham Shorey42 pointsPosted Dec 13, 2006, 1:47 AM EST