Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a Winform that divides out delivery time equally in a day. I have 6 textBoxes that I enter Lunch time for 3 shifts. I need it to exclude the start and stop time for lunch and pick up after so the times are still even. should i approach it differently like a csv file.

What I have tried:

I have searched the web with not luck on how to do it.
Posted
Updated 26-Nov-16 18:25pm

Quote:
should i approach it differently like a csv file.
There is no different approaches, it is a mathematical problem, you only need to get the data by whatever mean you want. A csv file will not be simpler than TextBox, the only reason to choose one or the other us if lunch time change or not.

The work time is from Shift.begin to Lunch.begin and from Lunch.end to Shift.end. There shouldn't be any difficulties here.

Explain your problem of something is not clear for you.

[Update]
Quote:
have not seen a straight forward solution to subtract the times
First solution: you use DateTime variables that will handle details for you.
Second solution: you do it yourself. The digits on left of ":" are hours, the digits on right are minutes. Transform to minutes (1 hour= 60 minutes) a,d then subtract.
 
Share this answer
 
v2
Comments
Member 12349103 26-Nov-16 23:28pm    
I can populate the information but have not seen a straight forward solution to subtract the times. I have been working on this for 2 mo. I'm new to code it could be done in a day for an experience coder. Thanks for the suggestion i will stay with text box.
Philippe Mori 5-Jan-17 14:57pm    
DateTime and TimeSpan have all necessary functions and operators for basic time computation. If you would read the documentation, it would help you a lot.
Patrice T 5-Jan-17 15:10pm    
So true.
C#
            var start_time = dateTimePicker1.Text;
            var start_time_array = start_time.Split(':');
            var today = DateTime.Now;
            var trailer_count = Convert.ToInt32(tbTrailer_Needed.Text);
            var minutes_apart = Convert.ToDouble(tbTime_Between.Text);
            var calculated_start_time = new DateTime(today.Year, today.Month, today.Day, Convert.ToInt16(start_time_array[0]), Convert.ToInt16(start_time_array[1]), 00);


var trailers = new List<trailer__time>();
            for (var i = 0; i < trailer_count; i++)
            {
                if (i == 0)
                {
                    calculated_start_time = calculated_start_time.AddMinutes(0);
                }
                else
                {
                    calculated_start_time = calculated_start_time.AddMinutes(minutes_apart);
                }

                trailers.Add(new Trailer__Time
                {
                    Trailer_Number = i,
                    Delivery_Time = calculated_start_time.ToString()
                });
            }

            dataGridView1.DataSource = trailers;
                    
        }
 
Share this answer
 
v4
Comments
Richard MacCutchan 27-Nov-16 3:02am    
Do not use double types for your values, as they are inherently inaccurate for this sort of problem. You should use all DateTime types and use TimeSpan to do calculations and comparisons.
Member 12349103 29-Nov-16 16:19pm    
Anyone else I cant find an answer.

thanks
Member 12349103 19-Dec-16 19:22pm    
Where can i find an example to do this in a TextBox?
Philippe Mori 5-Jan-17 14:59pm    
Go to school and listen to your teacher... or read some books.
Member 12349103 21-Jan-17 21:46pm    
i have accepted a solution little late on your snark

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900