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

List of times between two TimeSpans

I'm trying to create a list of time spans between 2 time spans. For Example 23:55 -> 00:10 should give me 23:55 00:00 00:05 00:10 This is my code but I get an out of memory exception var times = new List(); int interval = 5; TimeSpan…
totalitarian
  • 3,606
  • 6
  • 32
  • 55
-1
votes
1 answer

windows phone done and cancel buttons

Is it possible to access the built in 'done' and 'cancel' buttons to check which was touched/clicked. I am using the timeSpanPicker control and want to check if, when the control has been tapped, the user has confirmed a new time span or cancelled…
-1
votes
2 answers

Formatting TimeSpans

I am trying to format a TimeSpan with the following line of code: .ToString("[d.]hh:mm:ss") It throws a FormatException, but the exception goes away when I remove the :, the [], and the .. I also cannot include spaces. Does anyone know why this is…
TheGateKeeper
  • 4,420
  • 19
  • 66
  • 101
-1
votes
2 answers

TimeSpan not giving expected results

I am trying to log how long certain methods take within my ASP.Net application. On my services calls, I have a base class that has StartTimer and StopTimer methods. The idea is that I can start a timer, record a start time, and then stop the timer,…
Craig
  • 18,074
  • 38
  • 147
  • 248
-1
votes
3 answers

Converting a string into TimeSpan

I have been playing around with the Google Distance Matrix API, so far I've been able to get duration strings in the following format string a = "1 days 5 hours"; string b = "18 hours 10 minutes"; string c = "29 minutes"; etc.. My…
user2263162
  • 21
  • 1
  • 2
-1
votes
1 answer

TimeSpan will not parse some strings

I'm not sure what's going on here, but it will accept some timespans, but not others. Can someone show me a way to check for a vaild time span in this format 99:59:59. //50:30:00 is bad //50:20:00 is good try { TimeSpan ts = new TimeSpan(); …
Rikki B
  • 636
  • 8
  • 23
-1
votes
5 answers

date validation hotel reservation

hi iam creating a hotel reservation form and wanted to calculate total cost of stay by the nights stayed. it requires an arrival date and departure date but i want to add a validation so if the user inputs an incorrect format a message box displays…
-1
votes
5 answers

TimeSpan adding minutes to zero hour

I'm adding time span with interval size(suppose one minute) in a loop and whenever it gets 23:59 and at this point I'm trying to add one minute, it giving me result 1.00:00:00:00 something like this. How can i get continuous adding intervals when it…
nag
  • 920
  • 6
  • 27
  • 51
-1
votes
3 answers

VB.NET How to use TimeSpan to add time to another TimeSpan

My first timespan is: "00:01:03,160" and my second timespan is: "00:00:01,100" i want to do an addition or subtraction between 00:01:03,160 to 00:00:01,100 00:01:03,160 + 00:00:01,100 = 00:01:04,260 i think that the format is : hh\:mm\:ss\,fff
SSID
  • 15
  • 2
  • 7
-2
votes
3 answers

Not allowing a user to put "Clock Out" time < "Clock In" time?

Public void Fee() { TimeSpan span1 = TimeSpan.FromHours(dtmIn.Value.Hour); TimeSpan span2 = TimeSpan.FromHours(dtmOut.Value.Hour); TimeSpan span3 = TimeSpan.FromMinutes(dtmIn.Value.Minute); TimeSpan span4 =…
John
  • 81
  • 1
  • 4
-2
votes
1 answer

How to find subtimespan in a timespan like a string in python

I have a string of a timespan like this: timespan = '08.00-14:00' I want to know if this timespan is at least n hours, for example 2 hours: if timespan >= 2: do something
doduz
  • 5
  • 4
-2
votes
3 answers

Adding decimal years to a DateTime

When I encountered this I thought it would be a trivial challenge involved TimeSpans and basic DateTime arithmetic. Unless I have missed some really obvious I was wrong... How would you add 13.245 years to 3/22/2023 5:25:00 AM? The closest I get is…
MrEyes
  • 13,059
  • 10
  • 48
  • 68
-2
votes
1 answer

How do I get the total hours worked for this list of employees (and hours worked is a string)?

How do I get the total hours worked for the following list of employees? Live demo using System; using System.Collections.Generic; public class Program { public static void Main() { Console.WriteLine("Hello World!"); …
Rod
  • 14,529
  • 31
  • 118
  • 230
-2
votes
1 answer

TimeSpan.Parse misinterpreting "12:30". Any idea on how to deal?

I have a TimeSpan column, 'ThrEndT' in table 'PostThr' to fill. I want to put in "12:30" to reference to a user 12:30PM. Long story, TimeSpan is better option than DateTime here. (I thought) postThr.ThrEndT = postThr.ThrTime +…
Nick Fleetwood
  • 471
  • 1
  • 5
  • 22
-2
votes
1 answer

Match rows from one dataframe with some timestamp to rows aggregated over a time interval in another data frame

I am wondering if there is some vectorized trick to do this better than the trivial solution where one implements this in a loop and lots of binary searches: Dataframe 1 has a time field that contains arbitrary time stamps (microsecond resolution)…
jpp1
  • 2,019
  • 3
  • 22
  • 43