Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timespan division by a number

Tags:

I have a code generating a timespan to calculate a duration of some action. What I want to do is to take that result (the duration) and divide it by a number, any number.

How can I do that?

like image 371
Novak Avatar asked Apr 03 '12 13:04

Novak


People also ask

What is TimeSpan value?

A TimeSpan value represents a time interval and can be expressed as a particular number of days, hours, minutes, seconds, and milliseconds.

What is data type TimeSpan?

TimeSpan (amount of time) is a new data type that can be used to store information about an elapsed time period or a time span. For example, the value in the picture (148:05:36.254) consists of 148 hours, 5 minutes, 36 seconds, and 254 milliseconds.

How do I add time to TimeSpan?

Add() Method in C# This method is used to a get new TimeSpan object whose value is the sum of the specified TimeSpan object and this instance. Syntax public TimeSpan Add (TimeSpan t);


2 Answers

You can use ticks of the original timespan:

var res = new TimeSpan(origSpan.Ticks / aNumberAnyNumber); 
like image 157
Sergey Kalinichenko Avatar answered Oct 29 '22 04:10

Sergey Kalinichenko


try

TimeSpan X = ...;  var Result = X.TotalMilliseconds / WhatEverNumber; 

For reference see MSDN.

like image 38
Yahia Avatar answered Oct 29 '22 04:10

Yahia