timespan

Get Ticks per second and convert to String value?

How do I get number of ticks per second of DateTime.UtcNow and convert it to a String value? BAD QUESTION: try again http://stackoverflow.com/questions/3123894/get-ten-millionths-of-a-second ...

Get ten millionths of a second

How do I get the string value of the ten millionths of a second? "fffffff" http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx ...

TimeSpan of days in configuration?

It appears that ConfigurationElement of TimeSpan cant handle values larger than 23:59:59. Are there any workarounds? Is subclassing TimeSpan, and making a new TimeSpanValidatorAttrib even going to work? I need to handle timespans from a few minutes to a few days. I'm using the following configuration section [ConfigurationProperty...

Calculate the difference between two dates and get the value in years ?

Possible Duplicate: How do I calculate someones age in C#? I want to calculate basically the age of employees - So we have DOB for each employee, So on the C# Side I want to do something like this - int age=Convert.Int32(DateTime.Now-DOB); I can use days and manipulate then get the age...but I wanted to know if there some...

Formatting a negative TimeSpan

I'm doing some math with the Timespans in .Net, and occasionally the sum results in a negative Timespan. When I display the result I am having trouble formatting it to include the negative indicator. Dim ts as New Timespan(-10,0,0) ts.ToString() This will display "-10:00:00", which is good but I don't want to show the seconds so tri...

Sum TimeSpan array with a one-liner?

Is there a way to aggregate multiple aggregates to 1 time span? Dim times = { New TimeSpan(1, 0, 0), New TimeSpan(1, 10, 0), New TimeSpan(1, 50, 0), New TimeSpan(0, 20, 0), New TimeSpan(0, 10, 0) } Dim sum As New TimeSpan For Each ts In times sum = sum.Add(ts) Next 'That's what I desire: sum = times.Sum sum = times.Aggreg...

What exists in terms of a Java 'timeline' library?

I am interested in any library which can do the following: I have a time range: let's say 1995 to 2010 which I can classify in some way, let's say as "The Internet Era". I then want to be able to break that up further, say 2001-2010 as "The Google Era". Ideally, I'd like the time line to exist as some sort of list of timespans object...

TimeSpan and double rounding errors

Hello, I'm dealing with physical entities, such as time, speed and distance, and performing simple math, such as distance = time * speed, etc. Speed and Distance are double values rounded to 8th digit, and for Time values a .NET TimeSpan is used. Since TimeSpan rounds to a closest millisecond, I'm getting rounding errors, so I need to w...

Why has this particular TimeSpan format string stopped working in .NET 4?

Consider this code (prestuffed with an example): DateTime dt1 = DateTime.Parse("7/30/2010 9:33:29.1234567 AM"); DateTime dt2 = DateTime.Parse("6/30/2010 9:33:00.7654321 AM"); TimeSpan ts = dt1 - dt2; Console.WriteLine(string.Format( "{0:d.hh:mm:ss.ff}", ts )); This is representative of a piece of code that I've had working since .NE...

is there a smarter way to generate "time since" with a DateTime objects

i have this code to take a time in the past and generate a readable string to represent how long ago it was. I would have thought Timespan.Hours would give you hours even if its multiple daye in the past but it looks like it breaks it down into its seperate components (days, months, etc). How would i get total hours ago (even if its mo...

Calculating timespans for outages when I have only the results of failed calls

I'm writing a report that shows total downtime for our website. When a user visits our site and something's not working (ie the load balancer thinks our site isn't responsive), it sends visitors to a "Maintenance" page. The maintenance page logs to the database that it's been viewed and displays a friendly message to the visitor. That m...

Different behaviour between formatting strings for TimeSpan and DateTime

Hi all! While coding today, I noticed something odd with timespans and formatting strings. I was trying to print a timespan, for instance 01:03:37 as 1:03:37 (without the leading 0 for hours). So I used the format string h:mm:ss. This, however, gave me a leading 0. If I converted the TimeSpan to a DateTime and did the same thing again, ...

What is the proper way to format a TimeSpan as a countdown timer?

I have a timer that runs on the website. It will retrieve a timespan of how long a user has until their order expires. For the most part this works fine, the server will return the initial time remaining and the javascript will do the countdown. So it displays 2:30 2:29 2:28 Then for some reason, on some of the page loads (seems to hap...

How can a Timespan-Day last only for 8 Hours?

I have saved a duration in minutes and want to have an output "1 day 5 hours 30 minutes". Currently i add the minutes to a Timespan and do something like this: TimeSpan ts = new TimeSpan(0,0,1800, 0); Response.Write(ts.Days + "day(s) " + ts.Hours + " hour(s)" + ts.Minutes + " minutes"); But now i am only interested in the working-hour...

SQL time period query

I need to select from a table all rows that have date_added between CURDATE() and 6 weeks ago. Help please. ...

Format TimeSpan greater than 24 hour

Hi, Say I convert some second into the TimeSpan object like this. Dim sec= 1254234568 Dim t As TimeSpan = TimeSpan.FromSeconds(sec) How to format TimeSpan object into a format like the following: >105hr 56mn 47sec Is there any built-in function? or I need to write a custom function. Thanks. ...

Custom string formats of TimeSpan

I want to format TimeSpans in C# in this way: xxx day(s) yyy hours(s) zzz minute(s) Conditions: Extra seconds should be truncated day(s) is the largest unit I want. I want 34 days to appear as 34 days rather than 1 month 4 days etc. If timespan is less than one day, I dont want the day part to show up. Likewise if span is less than 1...

Arithmetic with PowerShell Timespans

PowerShell Timespans are great for quickly displaying durations, as in: $starttime = $(get-date) { do some processing here } write-host "Duration: $((new-timespan $starttime $(get-date)).tostring())" But if I did $loopcount iterations of processing during that timeframe, how do I divide the duration by $loopcount to get the average du...

Use String.Format on a TimeSpan to output only full seconds

I want to display the elapsed time between two dates in a string. Let's say I have the following code: DateTime date1 = DateTime.Now(); System.Threading.Thread.Sleep(2500); DateTime date2 = DateTime.Now(); TimeSpan elapsed = date2.substract(date1); Console.WriteLine("> {0:hh:mm:ss}", elapsed); What I expect: > 00:00:03 What I get...

Best approach/data type(s) for a date and two times in .Net 4

Hi all, I've got a method which takes some parameters and generates some XML to be sent to an [archaic] web service. I need to include in the XML: Date (yyyy-mm-dd) Opening time (hh:mm) Closing time (hh:mm) Now in the past when I've had to provide a date/time separately, I've taken in a single DateTime parameter and for...