Solved

From timestamps to time difference

Posted on 2011-09-26
1
247 Views
Last Modified: 2012-05-12
Hi there,

I have a history list which refers to any request that has been made on a certain website.
All request timestamps are in column A.
The value in column B is the user who made that request.
  history.xls

My goal is :
- for each user, get the connection duration by day, week or month

We consider that if there is 2 (or more) consecutive requests in less than 10 minutes, we can add the time difference as "connection time".
i.e.:
2011-07-04 10:16:20	326
2011-07-04 10:17:17	326

Open in new window

=> connection time = 0:57mn

Thank you for your suggestions !

Eric
0
Comment
Question by:eirikur
1 Comment
 
LVL 3

Accepted Solution

by:
anjos earned 500 total points
ID: 36599946
ie you can use this to get a timespan:
public TimeSpan dateTimeDifference(string d1, string d2)
        {
            DateTime startDate, endDate;

            if (DateTime.TryParse(d1, out startDate) && DateTime.TryParse(d2, out endDate))
                if (DateTime.Compare(startDate, endDate) < 0)
                {
                    TimeSpan span = endDate.Subtract(startDate);
                    return span;
                }

            return TimeSpan.Zero;
        }

And this to get a time difference:
public string makeTimeString(TimeSpan t)
        {
            string H = "", M = "";

            if (t.Hours < 10)
                H = "0";
            if (t.Minutes < 10)
                M = "0";

            H += t.Hours.ToString();
            M += t.Minutes.ToString();

            return H + ":" + M;
        }
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question