473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Calculating total time for a week

45
Hi All,

I am calculating totaltime of the employee for each day.I want weekly totaltime working hours.I am using for loop to calculate totaltime for 1 week.But i am storing Total time in String.How to add totaltime for week.
If i use DateTime i am getting date also but i want only time.

TotalTime - 9:00 for 1 day.

I should use Static variable to keep the Previous TotalTime in varible so that i can add previous and current day totaltime.

This is my code

Expand|Select|Wrap|Line Numbers
  1.  for (int i = 3; i < count; i++)
  2.                 {
  3.  string[] TimeSplit = SpliData(strData);
  4.                         //TimeIn.Add(Convert.ToDateTime(TimeSplit[0]));
  5.                         //TimeOut.Add(Convert.ToDateTime(TimeSplit[1]))
  6.                         string TimeValue = TimeSplit.ToString();
  7.                         string frmtimestring = TimeSplit[0];
  8.                         string toTimeString = TimeSplit[1];
  9.                         int frmTime = Convert.ToInt32(frmtimestring.Replace(":", ""));
  10.                         int totime = Convert.ToInt32(toTimeString.Replace(":", ""));
  11.                         if (frmTime > totime)
  12.                         {
  13.                             totime = totime + 2400;
  14.                         }
  15.                         string TotalTime = Convert.ToString(frmTime - totime).Replace("-", "");
  16.                         TotalTime = TotalTime.Substring(0, TotalTime.Length - 2) + ":" +TotalTime.Substring(TotalTime.Length - 2);
  17. }
Sep 29 '10 #1
2 2608
Frinavale
9,735 Expert Mod 8TB
When you have to do calculations that involve time you should stick with using DateTime structures and TimeSpan structures.

Store the start time in a DateTime structure variable (called something like startTime) and store the end time in a DateTime structure (called something like endTime).

You can subtract DateTime structures...but when you do this you get a TimeSpan as a result. The TimeSpan will include details on how many days, minutes, hours, seconds, milliseconds difference there was between the two DateTime objects.

For Example:
(VB.NET)
Expand|Select|Wrap|Line Numbers
  1. Dim startTime As DateTime
  2. DateTime.TryParse("9:00", startTime)
  3. 'you could also use: DateTime.TryParse("9:00 AM", startTime)
  4.  
  5. Dim endTime As DateTime
  6. DateTime.TryParse("17:00", endTime)
  7. 'you could also use: DateTime.TryParse("5:00 PM", endTime)
  8.  
  9. Dim workInterval As TimeSpan = endTime - startTime
  10.  
  11. Dim numHoursWorked As Integer = workInterval.Hours
  12.  
(C#)
Expand|Select|Wrap|Line Numbers
  1. DateTime startTime;
  2. DateTime.TryParse("9:00", startTime);
  3. //you could also use: DateTime.TryParse("9:00 AM", startTime);
  4.  
  5. DateTime endTime;
  6. DateTime.TryParse("17:00", endTime);
  7. //you could also use: DateTime.TryParse("5:00 PM", endTime);
  8.  
  9. TimeSpan workInterval = endTime - startTime;
  10.  
  11. Integer numHoursWorked = workInterval.Hours;
  12.  
-Frinny
Sep 29 '10 #2
Hi,

We have been using employee time card software from Replicon to calculate log-in and log-out time of our employees.

There are great benefits a business can get from this great software. You can use it to make instant payments and track your employees time spent on different tasks more accurately.
Aug 27 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: MLH | last post by:
I have tblMemberLogins with and fields. Any member may appear in the table numerous times. How can I sum up the total time spent logged in by any member in the table, I can extract the records...
2
by: Supra | last post by:
i know how to get filesize (using filelen) but don't how to get total time. i am using mpegs or songs. i can retreived filename but not total times in listhbox. i done in vb6 b4. 300 = 30 sec...
17
by: barkarlo | last post by:
I need help to make grand total time in continuous forms. to calculate total work time I use following formula =format(+1--nz();"short time"). but when I make grand total time in form footer (for...
2
by: Guizones | last post by:
Hello, I have one table that has a column called CallDuration. This columns has always the format "1/01/2000 12:01:38 AM". The date part "1/01/2000" I want to discard, and sum the time part to get...
2
by: vssp | last post by:
hai friends I have uploaded the video file to server .we need to get the total time of playing file duration and store the values to database. how can i get the total time for uploaded video file? ...
14
meLady
by: meLady | last post by:
Hello, Here I am having a little bit confusion about how to calculate the total time of steps of a process (for example: registering a new user for a website) in MS Access: - step1: entering a...
1
by: reshmaarora22 | last post by:
hi i have i table called Description which has details about StartTime , EndTime and ScheduleDate of the various Transaction occuring daily.I want to fetch total time spend on a particular...
3
by: John Torres | last post by:
how do you calculate total time hours? I have sub total hours for each day and I've been trying to total all the hours. I'm getting odd numbers. Thanks. John
0
by: progvar | last post by:
Hi I used the formula in xls sheet like = 985 / (2:26:25 *24) * 7.5 and i got answer = 7:38:47 and then i changed the format of cell into number and final answer is 3027 where 7.5 is total time...
1
by: visweswaran28 | last post by:
I created one crystal report in that i print time for each user. finally i want to calculate total time. so wat should i do to calculate total time. i tried with sum method......
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.