954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

add time in c#(visual studio 2005)

Hi Every one!
i have a data gridview consisting of four column
total_time,Start_time,End_Time,Day
all are of date/time data types.
i want to add the first to columns Total_Time and Start_Time and show the result into third column End_Time and the coresponding day in the fourth column Day.
the total_Time may consist of more then 24 hours. I am trying to do this for three days but i can't......
How i can do this in c#(visual studio 2005) connected to Ms Acces Database.
Thnx.....

ejazmusavi
Light Poster
42 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

You can either construct SELECT statement to do the calculation or override GridView DataBound event handler to perform the calculation, please mention are you working in web-based\windows-based application?

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

Thank you for ur reply.
I am working in window base application.
Thnx

ejazmusavi
Light Poster
42 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Good, please mention your SELECT statement.

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

my code to solve this problem is as below

TimeSpan spanTotal = ((DateTime)dataGridView1.Rows[i].Cells[2].Value).TimeOfDay;
TimeSpan spanTimeStart = ((DateTime)dataGridView1.Rows[i].Cells[3].Value).TimeOfDay;
TimeSpan spantTiemEnd = spanTimeStart.Add(spanTotal);

this add the two times but when the time exceed from 24 hours it stop. for example if i need to add 26:30Hours with 11:10 Am then it does not work

ejazmusavi
Light Poster
42 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

and what this time "26:30Hours" represents?!!!

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

26:30 Hours represent 26 Hours and 30 minutes which i want to add with 11:10 Am which represents a time of day.
Example i mean i want to add
(11:10 AM Monday)+(26:30)=(2:40 PM Tuesday)

ejazmusavi
Light Poster
42 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You