AboutNick Expertise I can answer questions regarding C#, C , SQL, Visual Basic, .Net Framework 2.0, general programming technique, and general algorithm development. My current area of focus is C#.
Experience C /VB programmer since 10th grade. I used to love video game development (still do, just don't do it anymore). Have real world experience in 3 companies for a total of about 2 years non-academic experience.
Organizations Keneisys (a security software company)
Education/Credentials BS in Computer Science with minor in Entertainment Technology.
Awards and Honors "The Next Bill Gates" gag award :-). College: Summa Cum Laude.
Expert: Nick Date: 3/13/2008 Subject: Kindly let me know the logic please
Question Hi Nick,
I have a small problem. I am supposed to calculate distance between two given times. However, I have one more problem. I have set up something called as interval. eg. The client can enter this field. If he puts the value of 10 as interval then I have to display him records of the vehicle for every 10 minutes and the distance travelled within these 10 mns.
Now I have populated a data table dt which consists of all records from a particular starting time and ending time
for (int i = 0; i < dt.Rows.Count - 1; i++)
{
StartDate = Convert.ToDateTime(dt.Rows[i][0].ToString());
AddDate = Convert.ToDateTime(dt.Rows[i + 1][0].ToString());
TimeSpan t1 = AddDate.Subtract(StartDate);
double t2 = t1.Minutes;
if (t2 >= interval)
{
//Calculate the distance between the startdate and adddate
//Display all the values
//Now the adddate should be the start date
StartDate = AddDate;
}
}
Now consider with an example
StartDate= "03/12/2008"
End Date="03/13/2008"
Now I have to get details for every 10 mns.
What I tried to do is put all the values that exists in the above time frame in a datatable.
Take the first records value as start date
Take the immmediate next record as add date
see whether the time difference is 10.
If yes then calculate distance between those two.
else
****
this is what I want
*****
i should not incremnt the value of start date
but the value of add date should be increased.
How to do that.
Kindly Help
Regards
Hema
Answer Hi Hema,
If I am correct, you have phrased this question in a much more complicated manner than is required. Is the following your question?:
"How do I increment an instance of DateTime by a given amount of time?"
If so, then the following code may be of use to you. It shows how to increment a DateTime by one hour.
DateTime d = DateTime.Now;
d = d.AddMilliseconds(1000 * 60 * 60);
Let me know if I have misinterpreted your question.