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);

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

If you are using DateTime, then you get the Date. TimeSpan might be better for what you want to do, or using a Stopwatch if you are timing things..

commented: Nice advice. +8

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.

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

If you are timing something, use the Stopwatch class, that's what it is for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.