How to modify from and to values in grafana - grafana

I am having troubles understanding how the following works
from=now-1h&to=1568789063000
but when I do
from=1568789063000-1h&to=1568789063000 it doesn't work.
I have tried doing it directly in the URL, doesn't work.
from=1568789063000-1h&to=1568789063000 and from=1568789063000-2h&to=1568789063000 shows me the same time range on the graph whereas
from=now-1h&to=1568789063000 and from=now-2h&to=1568789063000 shows me different time range in the graph.
Additionally, I also tried manipulating this by using the option Data link in the visualization where I tried using
from=${__value_time}-1h&to=${__value_time} and I don't plan to use __url_time_range becasue I want custom time range around one point.
Can please anyone explain what I am doing wrong or what am I missing?

The Unix timestamps you're using (1568789063000) all translate to the same time. So doing from=1568789063000&to=1568789063000 doesn't return a valid period of time as
1568789063000 - 1568789063000 = 0
now-1h and now-2h will show different time ranges because you're telling Grafana to start the graph either at one or two hours before the time that you're making the render request, even if the to time is always the same
As for the issue using the absolute timestamp with a relative "offset" (1568789063000-1h), this isn't allowed. Instead you should subtract 3600000 from the starting (from) timestamp which equals 1568785463000. So, if you do from=1568785463000&to=1568789063000, it should work instead of from=1568789063000-1h&to=1568789063000.
Similarly for -2h, you should subtract 7200000: from=1568781863000&to=1568789063000.

Related

Webi: How to use double slider input control with dates?

My boss asked me to add a double slider input control for the date information on a report on Webi.
We have several columns and two of them display a date (start and end date of procedure). So I need to have two double slider, one for each date.
I've been searching for a whole day now and I know that it is not directly possible to use double slider with dates, because double slider only works with values (measures) and dates don't have that.
But I managed to create two more variables on the business layer. I used the following SQL function:
CAST(currentDate as Bigint))
These variables are displaying the date as numbers (e.g. 1090101 for 01.01.2009 (format is "dd-MM-yyyy")).
And it is working great! But it displays the dates as number, which is not possible to use for work. No one will know which date is 1090101. I could perhaps let both columns (date as date and date as number) in the report, so people could check the date they want to filter with the input control and select the right number on the slider. This could be a workaround, but not a clean one, I think.
I tried to change the format of the date as number to a date format, but then I could not use the slider anymore (even if the variable is a number).
I looked for a way to change the formatting of the values displayed on the slider, but with no luck.
So I'm asking for your help. Does anyone know how I could make this work?
Is there really no solutions for such a useful way of filtering data? I mean, filtering data by an interval of dates is surely something people want to do quite often, I assume.
Thank you in advance for your time.
(Version Webi : SAP BusinessObjects BI Platform 4.2 Support Pack 8 Patch 6,
Version: 14.2.8.3671)
You could format your date value as year, month, day and then convert it to a number so the value you are filtering on makes a little more sense. Like this...
=ToNumber(FormatDate([Your Date];"yyyyMMdd"))
It will be better than just an arbitrary number, but certainly not perfect since you will have large chunks of your range for which there never will be any corresponding data (e.g. 20211232 through 20220100).
What is wrong with just a Minimum and Maximum input controls? They are more intuitive and simple to create. Sometimes what your user or boss asks for is a bad idea and/or just not possible.

Tableau, strange behavior for reference line

I'm attempting to show the results of an experiment. I'm using a calculated field and a parameter to create the following view, splitting the view by pre and post dates.
The trouble is the "Average" reference line...
None of the reference lines are placed at the actual Average for that time period (or any time period, from what I can tell). I know this because when I highlight the full date range the reference line adjusts:
Here's how I've set up the Average:
here's the calculation for post-reset (pre-reset is the same). [ reset-date ] is a hard coded parameter (the date the intervention began).
date( if [Friday Date] >= [reset-date]
then [Friday Date]
end)
Any idea what's going on here?
I was helped on the Tableau forum itself:
https://community.tableau.com/message/673000#673000
Instead of creating two date axis, I added one dimension to show pre and post.
See post at the link above for a full description, images, and a reference file.

Rails date loss of precision

I have an annoying issue with Rails/Active Record and dates that I'm trying to figure out. We're using date fields for composite keys, which I am turning into timestamps to make it easier for use as URL parameters. This is working fine, but I have inconsistencies when trying to lookup records after converting the timestamp back into a DateTime. When the object is serialised, the ID sent back looks something like 1401810373.197,63 where the first number is the timestamp with milliseconds, and the second value is the original ID that rails normally uses.
When a request is received with this ID, the timestamp is parsed using the following
... get timestamp from input ...
Time.at(Rational(timestamp)).utc.strftime('%Y-%m-%d %H:%M:%S.%3N')
This works as expected, and the queries produced using this also work as expected. The issue lies in that the date time produced here, is slightly different to the one on the original object. They're out by something like 1ms which I'm assuming is due to the loss of precision when using to_f to get the timestamp.
I did a quick test in a console with the following code to replicate it
Model.all.each do |m|
puts Time.at(Rational("#{m.to_param.split(',').first}")).utc.strftime('%Y-%m-%d %H:%M:%S.%3N') == m.created_at.utc.strftime('%Y-%m-%d %H:%M:%S.%3N')
end
The output of this shows multiple true and false values, so something is definitely going wrong in the conversion.
Currently, the to_param method simply converts the created_at field using to_f. I've tried changing this to "%.6f" % m.created_at.to_f but this hasn't changed anything.
Is there anything I can do to prevent this difference in times, as it's causing an array of issues.
This is currently running on Postgres, where the created_at column is a timestamp(3) column. We're using Rails 4.1 with jRuby 1.7.12
Ended up dropping the accuracy entirely. Now the database has a type of timestamp(0) and rails has been modified to not provide the milliseconds. Seems to be working :)

How to change the system date and time into correct time zone

I have two fields,
CreatedDate
UpdatedDate
It takes from the system date and time.. My sql server is located at UK. So when i see in site it is showing wrong time.. how to change this in mvc?
My details page, i am showing like following,
<strong>Date Posted:</strong>
<%:Model.CreatedDate%>
Please give me the ideas?
I would store your dates using UTC and then use that as a baseline for converting to the appropriate timezone for your region. This makes it flexible since you have a constant reference point.

How did this number become this datetime?

We have a vendor which one field in the database is a number and somehow in the app interface it shows the date,
I'm trying to figure out how is this conversion
Here is the data:
this number 15862 generates this date 06/05/2013
I have no idea how, the vendor told us it is NOT a custom logic conversion it was used a tsql function although I can't figure which one.
I tried using "convert" without success.
I don't think that's from a tsql function considering it's derived using the UNIX time epoch. Basically it's number of days since 1969-12-31
But you could get it using tsql like so:
select datediff(d,'1969-12-31','2013-06-05')
It looks like it's using a base-date of 1/1/1970 (actually 12/31/1969) and the number represents the number of days after that.
Most probably this is saved as an offset in days since 01/01/1979:
date('m/d/Y', 15862*3600*24) gives 06/06/2013 and
date('m/d/Y', 15862*3600*24-(3600*24) gives exactly 06/05/2013