How to get Ticks in system date? - sql-server

I need Ticks in Current date time, just print the Ticks only.
set #date = GETDATE();
I need this format output:
Ticks - 634513824000000000

You won't get precission you want. See: ##TIMETICKS
Returns the number of microseconds per tick.
The amount of time per tick is computer-dependent. Each tick on the operating system is 31.25 milliseconds, or one thirty-second of a second.
SELECT ##TIMETICKS
-- result: 31250

Related

Limiting datediff by Hours and Days

Long time lurker and now i have my first question:
I'm designing a SQL Report. One Task is to calculate the amount of minutes between two Times. They can be the same day or on different days. In the Database there are 4 Columns given
The Start Date (as Datetime e.g. 24.10.2017 00:00:00)
The Start Time (as Datetime e.g. 01.01.1899 11:25:00)
The End Date (formated as above)
The End Time (formated as above)
I'm calculating three Filds, all in Minutes
Days between: =DateDiff("n", Fields!StartDatum.Value,Fields!QualDatum.Value)
Minutes between: =DateDiff("n",Fields!StartZeit.Value,Fields!QualZeit.Value)
Adding those up: =Fields!QualiZeitTage.Value+Fields!QualiZeitMinuten.Value
All of this is working great and produces the desired output.
My Problem is, that i don't need the full time between those events. I only want to count minutes that are between 7:00 am and 8:00 pm. Also, i want to exclude Saturdays and Sundays. How would i go about limiting the datediff function to my desired times?
Second Problem: The Endtime and Date are only written when the event actually is finished. If it's still ongoing those Fields are empty producing a negative number (-1060764480 for example). Since i'm only using those to produce Boolean output on surpassing a certain length, it's no problem. I would like to handle that more "cleanly" though. Any thoughts?

InfluxDB "GROUP BY time" shifts time

I'm having a problem thats limiting me quite a bit. We are trying to sample our data by grouping time. We have millions of points and want to fetch every Nth point in a given interval. We have implemented a solution that calculates the time difference in this interval and then groups by it to receive the correct amount of points.
SELECT last(value) as value FROM measurement WHERE time >= '...' AND time <= '...' GROUP BY time(calculated_time) fill(none)
The amount of points returned seems to be correct, but the dates are not.
See the results below:
Without sampling
> SELECT value FROM "measurement" WHERE time >= '2016-01-01T00:00:00Z' AND time <= '2017-01-01T00:00:00Z' LIMIT 5;
name: measurement
time value
---- -----
2016-01-01T00:00:00Z 61.111
2016-01-01T01:00:00Z 183.673
2016-01-01T02:00:00Z 200
2016-01-01T03:00:00Z 66.667
2016-01-01T04:00:00Z 97.959
With Sampling
> SELECT last(value) as value FROM "measurement" WHERE time >= '2016-01-01T00:00:00Z' AND time <= '2017-01-01T00:00:00Z' GROUP BY time(23m) fill(none) LIMIT 5;
name: measurement
time value
---- -----
2015-12-31T23:44:00Z 61.111
2016-01-01T00:53:00Z 183.673
2016-01-01T01:39:00Z 200
2016-01-01T02:48:00Z 66.667
2016-01-01T03:57:00Z 97.959
I expect the data to be returned to have the correct timestamp as in the database, regardless of the time used in the aggregation function. Instead, the time returned seems to be a multiple of the aggregated time. That is, if my aggregation is GROUP BY time(7m) then the points seem to a multiple of 7 apart.
If there is no solution to my problem with influx, is there an alternative database I can use where I can accomplish this? The data in this example is uniform and evenly distributed, but this is not always the case. More often than not it will be randomly distributed (spans of seconds to minutes).

WSS4JOutInterceptor Timestamp: How to change expiration duration?

How do I change the duration of the timestamp? I seem to get five minutes as the default; I needed to change the duration to ten minutes.
<wsu:Timestamp wsu:Id="TS-36971e11-a696-4c24-a89a-45d6a562c594">
<wsu:Created>2016-01-21T17:59:33.442Z</wsu:Created>
<wsu:Expires>2016-01-21T18:04:33.442Z</wsu:Expires>
</wsu:Timestamp>
I needed to change the expiration time to ten minutes after the 'Created' time.
Here is what I found out:
Set the timeToLive property to the number of seconds to expiration (default: 300)
wss4jOutProps.put("timeToLive", 600);

$filter('date')(milliSecond, 'HH:mm:ss, mm/dd/yyyy'); returns wrong date when time zone is changed

I am working in java script's AngularJs.js framework.
I am using $filter service to convert milliseconds into corresponding date.
But when I change the time zone its corresponding date is changed(different to previous).
following is code.
$filter('date')(milliSecond, 'HH:mm:ss, mm/dd/yyyy');
Calculate millisecond to local millisecond
milliSecondLocal = milliSecond - new Date().getTimezoneOffset() * 60 * 1000;
$filter('date')(milliSecondLocal, 'HH:mm:ss, mm/dd/yyyy');

How can I get timestamp in minutes using PostgreSQL

When I send a form on my web, the insert query saves the current date on my DB using the function now().
Now, I'm trying to get this column in minute format to calculate other thinks that I need, but I don't know how to do that.
For example, I have this:
"2013-05-08 08:30:00"
And I want this (now 8.50):
"20" <- In minutes
Thanks
OK, let's suppose you have a table with a timestamp:
CREATE TABLE ex (t timestamp);
INSERT INTO ex VALUES ('2013-05-08 8:30'::timestamp);
And you want the difference in minutes between the column t and now(). You can get that using the extract function:
SELECT extract(epoch from (now() - ex.t)) / 60 FROM ex;
epoch is the number of seconds from the "epoch" for date and timestamp types, but is't just the number of seconds in the interval for interval types. By dividing it by 60 you get what you want (if you want an integer number of minutes just trunc it.)

Resources