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
2 answers

Used Custom Method with DateTime.AddDays Parameter

In arithmetic operation for DateTime a method called DateTime.AddDays Method (Double) Using this method could easy if we want use only days with out fraction (for example Complete days that will refer in double parameter with integer numbers) or…
Ammar
  • 91
  • 2
  • 13
-1
votes
3 answers

Compare timespan to integer

Is it possible to compare a timespan to an integer in C#? if say I want to know if a timespan is equal to 30 days, and if it is then do something?
Ida
  • 11
  • 1
-1
votes
2 answers

Calculation of sum of hours in 24h format with incorrect C#

I have a mistake in calculating the hours. The values you see below are taken from a database and my task with C # is to do the sum of the hours. I list the problems below: 1) Total wrong hours, 2) As you can see in the data grid view there is a…
riki
  • 1,502
  • 5
  • 17
  • 45
-1
votes
2 answers

Can I get the hour that a TimeSpan begins?

I'm have to get the initial and the last hour of a TimeSpan variable. Is it possible to obtain? I haven't found anything talking about this.
-1
votes
1 answer

Convert TimeSpan to Double

I'm having some trouble with convertion of timespan to double. That's the code I used to convert double value to timespan: int r = 150; string t = TimeSpan.FromHours(Convert.ToDouble(r)).ToString(@"dd\.hh\:mm\:ss"); It gives: t--> 6.06:00:00 Now…
Prithiv
  • 504
  • 5
  • 20
-1
votes
2 answers

How to figure out wether a range of timespan is between which range of timespan

Let's say I have two timespan ranges 07.00.00 - 18.59.59 19.00.00 - 06.59.59 Now i have a timespan range, let's call it a duration. public class Duration { public TimeSpan StartingTime{get; set;} public TimeSpan EndingTime{get; set;} } Which…
Egert Aia
  • 459
  • 2
  • 12
-1
votes
1 answer

MVC EditorFor Timespan is removing the seconds

The editor generated for my Timespan only includes hours and minutes. I would like it to be standard, i.e. hh:mm:ss. I would have thought the default would be that, which I've tried. I've also tried [DisplayName("Start Time")] …
user48408
  • 3,234
  • 11
  • 39
  • 59
-1
votes
1 answer

Convert 24-hour string value to timespan

I'm reading data from an excel file. The user can specify the time in one of the following formats: 1600 16:00 In the latter case, I can easily convert it to a timespan. How do I convert the first format to timespan? Is there a straightforward way…
devC
  • 1,384
  • 5
  • 32
  • 56
-1
votes
1 answer

Taking Screenshot after 1 minute

I have two questions: 1. How can I take screenshot after every 1 min, when a key is pressed E.g. 10:00: -> key pressed -> Img1 10:01: -> key pressed -> Img2 10:02: -> key pressed -> Img3 2. How can I iterate the image chain assuming my program…
J.Doe
  • 3
  • 3
-1
votes
1 answer

I have set up an interval for timer using timespan, but want it to fire more frequently

I've set up my timer as such and it works fine. However I need the interval to fire more frequently so that the clock counts down quicker (as it wouldn't be appropriate for the user to have wait for the timer to countdown in real time, as it is a…
L. Mitchell
  • 61
  • 1
  • 10
-1
votes
2 answers

Compare current time with lambda expression in WPF

I want to using lambda expression to compare current DateTime.Now with time retrieved from database (time). I try this: string time = DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") +…
Abdulsalam Elsharif
  • 4,773
  • 7
  • 32
  • 66
-1
votes
1 answer

How to calculate timespans using modular arithmetic?

This question is basically about representing modular arithmetic concept in code and using the modulo sign. So recently I did a popup for SCCM installation, which should give user time to install an app, the client requuirements were to show the…
Robert Mazurowski
  • 327
  • 1
  • 3
  • 17
-1
votes
2 answers

Binding TimeSpan to DateTime control (Entity Framework)

I am working with C# Winform and Entity Framework, My question is, Is there a way to bind a TimeSpan property to DateTime control? I have a DataGridView which is DataBounded to a entity framework DbSet. DbSet has a TimeSpan property which I binded…
Henry
  • 195
  • 1
  • 16
-1
votes
1 answer

Conversion between timespan and date using vb.net

I'm running an application in which I'm able to obtain the required times, however when I try to deduct one value from another it comes up with error message stating conversion from date type cannot happen to timespan. The variables I use are shown…
Satvir Singh
  • 61
  • 4
  • 16
-1
votes
1 answer

How to calculate timespan (days) between 2 dates from timepicker in a class

I am trying to pass 2 variables check in date and check out date from 2 different date time picker on a form. The goal is two calculate the number of day between the 2 dates. Here is what I have so far: From the form: Public Class…