I have the following piece of SQL code that does the following:
- Obviously looks at a datetime field (stored every 5 minutes)
-
Averages and rounds above-mentioned datetime field to hour. The result looks like this:
2012-02-11 16:00:00.000 2012-02-11 17:00:00.000 2012-02-11 18:00:00.000 2012-02-11 19:00:00.000
And here’s the code:
DATEADD(hh, DATEPART(hh, LogDetails.lastupdated),
DATEADD(d, DATEDIFF(d, 0, LogDetails.lastupdated), 0)) AS TimePeriod
This works like a charm and the related objects average out just fine. I now need to turn this datestamp into UNIX Timestamp (for Flot charting purposes). Can someone help a bit here? Whatever I seem to be doing isn’t working, all the UNIX timestamps come in the same.
EDIT: This is finally working !!
DATEDIFF(second, '1970/01/01 00:00:00',
DATEADD(hh, DATEPART(hh, LogDetails.lastupdated),
DATEADD(d, DATEDIFF(d, 0, LogDetails.lastupdated), 0))) as UXTIME
Working Example: