DB2 timestampdiff assumption of months - db2

I have query that get timestampdiff but from understanding of the function of timestampdiff that it have assumption of 30 days a month so my question is there a way to make it more accurate or way to make it more accurate to consider the timing in months that have less than 30 days or more than 30 days to get the accurate results, i been searching for information on this but wouldn't able to find any, any one got into that more.
Thanks!!

Related

Date delta human readable format

I looking for a way to output how old something is for some reporting. I'm pretty open to approach, libraries, packages, and languages. Though bash, golang, and python would be preferred. I have already researched many different ways to do this. Though I keep seeing the same results which is not my ideal output. The outputs I am seeing are something like 45 days ago, or 1.06 months ago.
I'm looking for a way to output hours, days, weeks, months, and years. And example of this output would be "Last ran: 1 month, 2 weeks, 4 days, and 9 hours ago". Right now I'm currently getting the dates as epoch timestamps from bash date tool. So I can do any kind of conversion necessary to input. For sake of example here are some inputs: 2020-03-19T05:12:14, 2019-08-27T08:47:27, 2020-05-12T11:10:18, 2020-02-01T07:40:01. I'm trying to get how old these time stamps are from current time/date. So essentially what date outputs. Or other language equivalent.
More examples to demonstrate what I don't want echo $(( ($(date +%s) - $(date -d "2020-08-27T05:47:27" +%s) )/(60*60*24) )) => 16 Instead I want 2 weeks and 2 days. Same for something over a month or year old. Hours is the smallest increment that I really care about.

Given a fixed (but non-linear) calendar of future equipment usage; how to calculate the life at a given date in time

I have a challenge that i'm really struggling with.
I have a table which contains a 'scenario' that a user has defined, that they will consume 'usage'. For example, how many hours a machine will be turned on for.
In month 1, they will use 300 (hours, stored as an integer in minutes), Month 2 100, Month 3 450 etc etc etc.
I then have a list of tasks which need to be performed at specific intervals of usage. Given the above scenario, how could I forecast when these tasks will be due (the date). I also need to show repeat accomplishments and the dates.
The task contains the number of consumed hours at the last point of accomplishment, the interval between accomplishments and the expected life total the next time it is due (Last Done + Interval = Next Due)
I've tried SO many different options, ideally I want this to be compiled at run time (i.e. the only things that are saved into a permanent table are the forecast and the list of tasks). I have 7-800 scenarios, plus given the number of pieces of equipment, there are 12,000 tasks to be carried out. I need to show at least the next 100 years of tasks.
At the minute, I get the scenario, cross apply a list of dates between now and the year 2118. I then (in the where clause) filter out where the period number (the month number of the year) isn't matching the date, then divide the period usage by the number of days in that period. That gives me a day to day usage over the next 100 years (~36,000 Rows) When I join on the 12000 tasks and then try to filter where the due at value matches my dates table, I can't return ANY rows, even just the date column and the query runs for 7-8 minutes.
We measure more than just hours of usage too, there are 25 different measurement points, all of which are specificed in the scenario.
I can't use linear regression, because lets say for example, we shut down over the summer, and we don't utilize the equipment, then an average usage over the year means that tasks are due, even when we are telling the scenario we're shut down.
Are there any strategies out there that I could apply. I'm not looking for a 'Here's the SQL' answer, I'm just running out of strategies to form a solid query that can deal with the volume of data I'm dealing with.
I can get a query running perfectly with one task, but it just doesn't scale... at all...
If SQL isn't the answer, then i'm open to suggestions.
Thanks,
Harry

Grafana sumarize sum resolution

Grafana 3.1.1 with a whisper backend.
I am trying to use summarize to keep track of how many minutes during the day one if my parameters is set to 1.
Here is the statement that I am using:
summarize(thermostat.living_room.heatstate, '1d', 'sum', false)
It always display much less of a total than expected. To troubleshoot I changed the statement to:
summarize(thermostat.living_room.heatstate, '1h', 'sum', false)
If my time range is 6 hours or less then the summarize works as expected. If the time range is 12 hours or higher the total reported by summarize is much smaller than expected.
It appears to me that if I try to sum for 1 a day period it is not retrieving all of the data points for the day so my data is much smaller than expected. I have not found any information on the grafana site that talks about how to change this behavior.
Thanks,
Louis
It's not Grafana problem - you should set up your retention and aggregation in Graphite properly. Please check Graphite documentation or that summary.
I think you need to keep your points for at least 1 day unaggregated, so, if you sending your temperature once per minute, you should have retention = 1m:1d, ...

MongoDB Schema Feedback (Historical Data)

Nested Schema
Flat Schema
We have spent a considerable amount of time researching the best direction to go for schema design, and are stuck between the above two designs. Obviously, queries for data will be quite difficult, but the maximum number of steps required to reach an point of data would be 68 (1 yr, 12 months, 31 days, 24 hours).
The second design would allow for much more simple queries to find relevant data, but the maximum steps would be 8,760 depending on where the data is located.
We plan to hand LARGE amounts of historical data in the future, but it will take us multiple years to gain enough traction to get to that point.
Questions:
Is the number of steps to find the data even important at this point?
Would it be difficult to move to a new architecture in the future if speed/steps became an issue?
Is there a better approach to historical data that we're missing?
Any other feeback/suggestions/wisdom is definitely appreciated.

100+ dates in different timezones, calculate which 2 dates present day is between...more calculate

I am really having a heck of a time figuring out which way I should do this. Been coding objective-c for 4 months now, well trying to at least.
I have about 100+ different dates spanning 2012, down to the second, in multiple timezones. What I need is:
to grab the present time/date, see which 2 dates in my 100+ list it is between and give me time spent and time remaining.
to know which 2 dates it is between no matter what timezone a user is in.
all calculations need to take in consideration of daylight savings time. Which the dates and times of DST change is different depending on the timezone and country.
a user in Hawaii will have the same time remaining and spent as a user in England.
ablility to convert all times to local user time.
have this all realtime. have the clock or timer counting down to the second.
I have tried NSDate. Then I searched this site and found NSDateFormatter. I played with that for what seems like days. Then another search I found NSDateComponents. Do I put my 100+ dates in a multidimensional array. Do I convert everything to GMT first or can xcode do that for me. Or do I convert everytime to seconds since 1970. I am just lost on what would be the best most practical way of doing this.
Any help, thanks so much!!
I am not an iOS programmer, but if you could convert everything to the same time zone (MST, EST, GMT, whatever), then that would make your job far easier. Converting between time zones runs in constant time as there is nothing more involved than simple addition/subtraction.
As for DST, if you convert to MST or EST (as opposed to MDT or EDT), you inherently remove DST. What exactly do you mean by "take in consideration of DST?" I could help much more if you could provide that.