Question

I've been struggle with this for a while and hope someone can give me an idea to tackle this.

We have a service that goes out and collects Facebook likes, comments, and shares for each status update multiple times a day. The table that stores this data is something like this:

PostId        EngagementTypeId     Value   CollectedDate    
100             1(for likes)        10       1/1/2013 1:00 
100             2 (comments)        2        1/1/2013 1:00
100             3                   0.       1/1/2013 1:00
100.            1.                  12       1/1/2013 3:00
100.            2.                  3.       1/1/2013 3:00
100.            3                   5.       1/1/2013 3:00

Value holds the total for each engagement type at the time of collection.

I got a requirement to create a report that shows new value per day at different time zones.

Currently,I'm doing the calculation in a stored procedure that takes in a time zone offset and based on that I calculate the delta for each day. If this is for someone in California, the report will show 12 likes, 3 comments, and 5 shares for 12/31/2012. But if someone with the time zone offset of -1, he will see 10 likes on 12/31/2012 and 2 likes on 1/1/2013.

The problem I'm having is doing the calculation on the fly can be slow if we have a lot of data and a big date range. We're talking about having the delta pre-calculated for each day and stored in a table and I can just query from that ( we're considering SSAS but that's for the next phase). But doing this, I would need to have the data for each day for 24 time zones. Am I correct (and if so, this is not ideal) or is there a better way to approach this?

I'm using SQL 2012.

Thank you!

No correct solution

OTHER TIPS

You need to convert UTC DateTime stored in your column to Date based on users UTC time. This way you don't have to worry about any table that has to be populated with data. To get users date from your UTC column you will use something like this

SELECT CONVERT(DATE,(DATEADD(mi, DATEDIFF(mi, GETUTCDATE(), GETDATE()), '01/29/2014 04:00'))) 
   AS MyLocalDate

The select statement above figures out Local date based on the difference of UTC date and local Date. You will need to replace GETDATE() with users DATETIME that is passed in to your procedure and replace '01/29/2014 04:00' with your column. This way when you select any date from your table it will be according to what that date was at users local time. Than you can calculate other fields accordingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top