DRUID : Get Number of days for a given date range to get average - druid

Need to have the total number of days for a given interval. I have already tried using distinct of dates for the purpose. It fails because for some days data is not present. Once I have the number of days for the given date interval I will be able to find the daily average.
Any other approaches is also welcomed

Related

MS Access: How to find the number of days between consecutive dates (same column) regarding one ID?

Using MS Access, I'm trying to find a formula or a function that returns the number of days between consecutive records. i.e. how many days each sum has worked.
and if it was the last date in the group, I want the formula to return the number of days till the current system date.
image for the desired output

Flatline: How to calculate days between two dates

I want to add a calculated field in a BigML datasheet with the result of days between two dates.
I'm trying to figure out how to calculate the number of days between two date fields with Flatline language but I don't know how to do it even reading the doc.
Any clue about how create this calculated field?
PS: Somebody with enough reputation could create and add tags "bigml" and "flatline"?
Currently, the only way to subtract dates is by first transforming them to an
epoch (number of milliseconds since 1970) and then computing the difference:
(- (epoch "12/03/1990") (epoch "01/01/1988"))
That will give you the number of milliseconds between the two dates, which then
can be transformed to other units. What that won't give you is of course the
difference in calendar days: we don't have yet in Flatline a way of subtracting
calendar dates. But it shouldn't be too difficult to add them if it's a feature
you need :)

Trying to Average number of accounts by hour, day of week, and month

I'm in healthcare and we're trying to assess the number of discharges we have per hour of day, but we'd also like to be able to filter them down by day of week, or specific month, or even a particular day of week in a particular month (e.g. " what is the average number of discharges per hour on Mondays in January?")
I'm confident that Tableau can do this, but haven't been able to make the averages show up in my line graph... every time that I convert it from COUNT to AVG, the line simply goes straight. I got close when I did a table calculation to find the Average (dividing the count per hour by the number of days captured in the report), but when I add a filter for either the month or day of week, selecting one of the options of the filter reduces the total number that is being counted, rather than re-averaging the non-filtered items. (i.e. if the average of the 7 days of the week is "10" for a particular hour, and I deselect the first three days of the week, it's now saying that my average for that hour is roughly 6, despite the fact that all of the days are very close to 10 at that hour.)
Currently, my data table has the following columns:
Account#/MonthYear/HourOfDay/DayOfWeek
ex.12345678/ Jan-17 / 12 /Sunday
I would just create a few calculated fields to differentiate the parts of the calendar you might want to filter/aggregate on. Mixing the month and day of the week with filtering is pretty straight forward with the calculated fields. Then do standard summing to get what you are looking for because an average count of records is always one unless you are throwing some other calculation into the mix. I threw a quick example up on Tableau Public for you to get the idea.

Calculating the difference between two dates using age and extract gives differing results in Postgresql

I'm using Postgresql (on Amazon Redshift), and I need to calculate the difference between two dates and then use that value in a formula to compute a ratio, so the date difference needs to be translated to a numeric value, preferably a float or double precision.
I have two dates: 1/1/2017 and 1/1/2014. I need to find the difference between these two dates in number of days.
When I use the age function I get 1080 days:
select age('2017-01-01','2014-01-01')
However, since age returns an interval and I need to work with a numeric result, I am using EXTRACT to convert the final value. I chose epoch since I wasn't able to find any other value for EXTRACT that would yield the number of time units between the two dates. This formula yields 1095.75 days (the divisor is the number of seconds in a day):
select extract(epoch from age('2017-01-01','2014-01-01'))/86400
Why am I getting a difference of 19.75 days when using age vs using extract?
Did you try
select '2017-01-01'::date - '2014-01-01'::date;
The difference between two dates is number of days in integer
1080 is the figure you would get if every month was 30 days long (36 months by 30 days equals 1080), as it would be if you used justify_days (either explicitly or if the DBMS called it implicitly). You don't say how you're getting this 1080 figure since I believe the duration would normally just print out something like 3 years, but that seems the most likely case
1095.75 seems the more correct figure, being 365.25 days multiplied by three years.
Out of those two, I would go with the latter method.
Although, as pointed out at http://www.postgresql.org/docs/8.1/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT, calculating the difference between two date types should yield the number of days:
select dtend - dtstart from somewhere
Redshift release notes say they recently released a months between function which looks similar to oracles months between function if that's what you're looking for. http://docs.aws.amazon.com/redshift/latest/dg/r_MONTHS_BETWEEN_function.html

How can I find out the number of days in between two dates in python

I have a problem where I need to find the number of days between any two given dates from a list of dates is there anywhere to find out the number of days between the given dates.
the given dates are:
06/06/2012
08/08/2012
10/10/2012
12/12/2012
and the last day of feburary
The thing you're looking for is deltatime; in particular, it is what type you get when you subtract 2 date(time)s.