Questions tagged [timespan]

An elapsed measurement of time between two events or during which an event, program or a function continues. Also known as a timedelta or a duration.

A timespan is an elapsed measurement of time between two events or during which an event, program or a function continues.

It is also known as a timedelta or a duration in many programming languages.

  • For most intervals of time, this is calculated by:

    EndTime - StartTime
    

    This works especially well for half-open intervals that are used by time-only ranges, or date+time ranges.

  • However, be careful with date-only ranges. Typically these are expressed using fully-closed intervals, such as Jan 1 to Jan 2 to represent two days. This is calculated by:

    EndDate - StartDate + 1
    

See also the and tags.

1171 questions
-1
votes
3 answers

How to calculate Sum of Peak and Offpeak hours in List

I have a List. The ObjectInstance is a class, which has two TimeSpan attributes: StartTime and EndTimes. The start and end times can be anywhere between 8am and 10pm. Anytimes after 5pm is off peak time, else it is a peak time. I…
t_plusplus
  • 4,079
  • 5
  • 45
  • 60
-1
votes
2 answers

Resetting a countdown to date timer to another date when it ends

Ok so what I want to do is when then countdowns ends which means reach the endTime I've put this in 2 days, I want to reset and add another 7 days and keep doing that if possible. I've tried using if(endTime.Subtract(DateTime.Now) = 0) { …
Falcon
  • 3
  • 1
-1
votes
2 answers

How to get the time-span of all the datetime data in my datagridview

The scenario go's like that, above and this; I have a database, which I displayed on my datagridview. I already added the timespan of each row (timeIn and timeOut) and stored it on a textbox. Now, I wanted to add and display all the total timespans…
pruuylan
  • 86
  • 1
  • 1
  • 10
-1
votes
1 answer

Need to correct time span string format

I have a time span string as 1.21:00:00 it means 45 hours and i need it as 45:00:00 and i use following method from Need only HH:MM:SS in time span string it works perfectly for this above problem but when i change the string as …
Waqas
  • 847
  • 4
  • 14
  • 36
-1
votes
1 answer

Converting DateTime (DD MM YYYY HH MM SS) to Timespan like (DD MM YYYY HH MM SS) in c#

Is it possible to exactly clone the DateTime value to Timespan data type. I converted the datetime to timespan by subtracting to min value. However, how do it display in DD MM YYYY HH MM SS format. TimeSpan timeSpan = (DateTime)startTimeValue -…
Darey
  • 497
  • 4
  • 24
-1
votes
3 answers

How to find total from a concatenated value?

I have two concatenated values such as string BreakOut = "10:15 Mintes"; string BreakIn = "10:30 Minutes"; I want result as Total=15 Minutes It is a time difference calculation. But values are not in a time format it is in a string format. How…
Semil Sebastian
  • 111
  • 1
  • 5
  • 18
-1
votes
2 answers

TimeSpan rounding on toString() C#

I measure the Time of a wav File and got it back in a TimeSpan. When I look into the Timespan the totalSeconds value is the exact time i need! For example: TotalSeconds = 6.6999999999999993 When I write it into a File, it will be roundet to 6.7! I…
-1
votes
3 answers

Get days between first day of a month and a specified week and week day

I've the following problem: I'm try to calculate the days between the first day of the actuall month and a week and his week day. For example: actually it's february. I'll have the days between the first day of this month and the second wednesday.…
Marcel Hoffmann
  • 973
  • 1
  • 8
  • 15
-1
votes
1 answer

Calculate months between actually month and a specific one

I've a little question. How I can calculate the months between the current month and another given month? For example: now it's February, I want to know, how many months are between February and let's say January. Is there a clean way to do this?
Marcel Hoffmann
  • 973
  • 1
  • 8
  • 15
-1
votes
1 answer

TimeSpan default value format

I don't know how to hardcode in a time value into the timespan datatype? How do I do this? MY error below is that it will not accept '13:00' for the timespan value. Clock is the class. The date also will work. Like, do I use parenthesis to make the…
crsMC
  • 635
  • 3
  • 11
  • 24
-1
votes
2 answers

Whats the fastest way to find time diff

Whats the fastest way in R to find time difference: diff of row 1 to 2, 2 to 3, 3 to 4 and so on. Or timespan from 1 to 2, 2 to 3, ... In the end I heading for a function that shows all diffs/timspans e.g. > 7000ms HH:MM:SS:MIS*…
Teletubbi-OS X
  • 391
  • 1
  • 3
  • 13
-1
votes
4 answers

MessageBox.Show(TimeSpan)

i would like to show a TimeSpan in a MessageBox but am getting an error: DateTime date1 = new DateTime(byear, bmonth, bday, 0, 0, 0); DateTime datenow = DateTime.Now; TimeSpan age = datenow - date1; MessageBox.Show(ToString(age)); Error 1 No…
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
-1
votes
1 answer

asp.net mvc timespan format

I use in my view the following code reservation.HeureRepas.ToString(@"hh\:mm") and so I get for example: 14:45 But I would like to get a "H" in place of the column as 14H45
Alain BUFERNE
  • 2,016
  • 3
  • 26
  • 37
-1
votes
2 answers

Taking local time and counting down the remaining hours of the day until 12:00 AM

I've been stuck on this for awhile, I'm not even sure how to begin it because I'm a total noob with C#. At first I was utilizing DateTime.Now in order to get my local time, and tried to use that with TimeSpan in order to get how many hours are left…
user3708761
  • 275
  • 1
  • 6
  • 14
-1
votes
2 answers

How to get the timespan between two time in xp using C#

I am developing the C# windows application which needs to be run in windows XP. However the timespan concept is working in windows 7 and later versions the XP is not supporting it. TimeSpan diff = DateTime.Parse(dataGridView1[2,…