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
-2
votes
1 answer

How can I save string value to sql server db datatype as time(7)

I have to save a time to sqlserver2008 db as time(7) data type which is in string format in code behind.how can I convert it to that data type.My code getting error string time='9.30 pm'; modal db=new…
Safeena
  • 395
  • 2
  • 7
  • 21
-2
votes
1 answer

How to make 8 hrs as a day in timespan

The TimeSpan default day considers 24hrs as 1 day. I want to have 8 hrs as 1 day. So that If I give 1 day it should consider it as 8 hrs not 24 hrs. And if I give 23 hrs it should consider it as 2 days and 7 hrs. ` Task T1 =…
Nishanth Bhat
  • 56
  • 1
  • 7
-2
votes
1 answer

Calculate timespan between 2300 and 0100

I wonder how I can get the duration between 2300 and 0100, which should be 0200, but it returns 2200. Im working on an application with Xamarin.Forms and use two TimePickers which returns a TimeSpan. private TimeSpan CalculateDuration() { var…
user2236165
  • 741
  • 2
  • 11
  • 24
-2
votes
1 answer

Compare two data formats(24h and 12AM/PM) in C#

I have following strings: string s1 = "dd/mm/yyyy hh:mm"; // 24H format string s2 = "mm/dd/yyyy hh:mm:ss AM/PM" //12H format I need to compare them in my test (it means that i need to convert s1 to s2 or viceversa). Please help!
-2
votes
1 answer

Take data every 2 seconds MySql

I would like to get the data for every 2 seconds and get the average data if they have same time. For example : Number value Time [ 1] [20.1000] '2014-04-07 17:11:04' [ 2] [20.2000] '2014-04-07 17:11:05' [ 3]…
Ryvo
  • 3
  • 1
-2
votes
2 answers

Timespan not showing up

I cannot seem to get my code to calculate the amount of minutes between 2 datetime fields: private void button4_Click(object sender, EventArgs e) { string startTime = "5/1/2008 1:00:00 PM"; string endTime = "5/1/2008 3:00:00 PM"; …
PriceCheaperton
  • 5,071
  • 17
  • 52
  • 94
-2
votes
4 answers

Calculating time difference and keep on adding the difference to a label

I am working on a program that calculates the difference between two given times. The difference between two times is calculated with button1 event handler and is displayed in label as shown in the windows form layout shown below. This is my…
Tacit
  • 890
  • 6
  • 17
  • 42
-3
votes
1 answer

How to check if a timespan in negative. C#

The title says it all. I'm subtracting two DateTimes and I want to see if the returned Timespan is negative. How do I do this? // dt1 and dt2 are DateTimes. TimeSpan ts = dt1.Subtract(dt2); ts.isNegative() // or something like that
-3
votes
1 answer

Sum times over 24:00 in C#

I want to collect a few hours, but if sum is over 24:00 I take as like it: 1.01:20 How can it in c#: 23:00 + 02:00 = 25:00 ? Best regards
-3
votes
3 answers

Random time in C#

I need to generate custom random time in c# - not to random for a few minutes but only for 15 minutes intervals, for example - not to get 17:11 but 17:15. How can I generate this? I'm new to this issue. Thank you
hello
  • 23
  • 9
-3
votes
1 answer

Very flexible string format for TimeSpan

I want to implement the most flexible string format for a TimeSpan object. Suppose you've this code: string format = "................."; TimeSpan ts = TimeSpan.FromSeconds(7200); Debug.WriteLine(ts.ToString(format)); I want to specify a parameter…
Igor Damiani
  • 1,897
  • 9
  • 12
-3
votes
3 answers

Get undertime and overtime automatically

Could you please help me? I'm trying to create an attendance system wherein the undertime and overtime will be automatically computed, but there's an error. For example the employee's scheduled out is 11 PM, and their overtime 12 AM which is 1 hour,…
Manjay
  • 39
  • 1
  • 10
-3
votes
6 answers

How to pass "00:00:00" if value in timespan is null?

I am trying to sum my timespan. My logic is working absolutely fine, he only problem is if value is NULL then my application breaks. I want to pass "00:00:00" as my time-span if value is NULL. My following code is not working: @Model.Sum(x=>…
-3
votes
2 answers

c# How to truncate milliseconds with timespan?

I want to display a float that represents the timer and I am trying to format it like this: 00:00:00 (Minutes:Seconds:Milliseconds) public static string ConvertToTime(float t){ TimeSpan ts = TimeSpan.FromSeconds(t); return…
Mc Midas
  • 189
  • 1
  • 5
  • 17
-3
votes
3 answers

DateTime to TimeSpan from FileTime epoch?

Given the code var dt = new DateTime(2015, 5, 6); var ts = dt.Subtract(new DateTime(1601, 1, 1)); Considering in this code there is a subtract of a new DateTime(1601, 1, 1) which is the epoch for Windows FileTime, is there a better way to achieve…
codiac
  • 1,857
  • 4
  • 18
  • 31