0

I want find the number of hours in azure table storage

public UserTimeSheet GetTotalHoursByYear()
    {
        CloudTable cloudTable = GetCloudTable();
        var query = new TableQuery<DynamicTableEntity>()
        {
            SelectColumns = new List<string>()
        {
            "SignInTime", "SignOutTime"
        }
        };
        var queryOutput = cloudTable.ExecuteQuerySegmented<DynamicTableEntity>(query, null);

        var results = queryOutput.Results.ToList();
        foreach (var entity in results)
        {

        }
        return null;// results.ToList();
    }

I have return the code which select 2 dateTime columns. But i am not getting how get differnce of hours and sum it up. Please me to solve this.

Niranjan S
  • 132
  • 9
  • You can calculate the difference between two DateTime variables using the explanation showed in this answer https://stackoverflow.com/questions/2821040/how-do-i-get-the-time-difference-between-two-datetime-objects-using-c. I suppose that work with the columns is not the problem – rlm96 Jul 08 '20 at 07:51

1 Answers1

0

Please use the code below(and please feel free to modify the code to meet your need):

        //other code.

        var queryOutput = cloudTable.ExecuteQuerySegmented<DynamicTableEntity>(query, null);

        var results = queryOutput.Results.ToList();
        foreach (var entity in results)
        {
            var start = DateTime.Parse(entity.Properties["SignInTime"].StringValue);
            var end = DateTime.Parse(entity.Properties["SignOutTime"].StringValue);                

            var diff_hour = end.Subtract(start).Hours;
            Console.WriteLine("the hours between signIn and signOut is: " + diff_hour);
        }

Here is the test result at my side:

enter image description here

Note:

In my table, the type of SignInTime and SignOutTime is String, not DateTime. And if you set the 2 columns' type as DateTime, you just need a little change to my code.

enter image description here

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60