How can I set the time to 00:00:00, now i set it to
DateTime startTine=DateTime.Now
but i want to show the time as 0 everytime and run the calculation from that(0)starting time........

DateTime startTime = new DateTime(2010, 10, 31, 0, 0, 0);

Hi Momerath thanks and is there is a way that I can get only the hours,min,sec not the date as the start date like 00:00:00

To set the dateTime to 00:00:00 you can only do:

DateTime startTine=DateTime.Today;

Where exactly do you use this code - in what kind of calculation? If you are doing with counters, its better to you TimeSpan as Momerath said a post above.
Give me some more code, maybe we can help you out to get the best possible solution.

Edited 6 Years Ago by Mitja Bonca: n/a

To set the dateTime to 00:00:00 you can only do:

DateTime startTine=DateTime.Today;

Where exactly do you use this code - in what kind of calculation? If you are doing with counters, its better to you TimeSpan as Momerath said a post above.
Give me some more code, maybe we can help you out to get the best possible solution.

Hi Mitija,
I want to calculate the total elasped time when the user enter a positive or negative number in the textbox and clicks the evaluate button,so i want the starting time as 00:00:00 and suppose if the user want to calculate with another number like
00:00:00 starting value
+3:00:00 first value
-2:00:00 second value

the total elasped time should show as 1:00:00

.....the code i have now is as follows

public string TimeElasped( DateTime strStartingValue, DateTime strTimeAddSubtract)
{
TimeSpan duration = strTimeAddSubtract - strStartingValue;
string timeElasped = string.Format("{0} Hours,{1} Minutes,{2} Seconds",duration.Hours,
duration.Minutes,duration.Seconds);
return timeElasped;
}
private void button1_Click(object sender, EventArgs e)
{
DateTime strStartingValue = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,0,0,0);
DateTime strTimeAddSubtract = DateTime.Parse(input.Text);
label1.Text = input.Text+ "=" +TimeElasped(strStartingValue, strTimeAddSubtract);
label1.Visible = true;
label2.Text = "Total Elasped Time is "+TimeElasped(strStartingValue, strTimeAddSubtract);

}
I know the code will not be good....i am a beginner and i really wanted to study c#....thanks in advance

Edited 6 Years Ago by micahgeorge: n/a

This article has been dead for over six months. Start a new discussion instead.