Calculate Overtime Based On StartTime And StopTime - ms-access

I have a table where I register the duration of events that take place in an Auditorium of the company I work in. The table has all the event data includind the TimeStart field and TimeEnd field.
Our technician shift ends at 6pm.
So if an event duration ends beyond 6pm, I need to track the overtime the technician worked.
Can anyone help me with this matter?
Thanks to everyone in advance,
Hope your all safe.

That will be:
ShiftEnd = #06:00:00 PM#
Overtime = CDate(DurationEnd - ShiftEnd)
If over-Midnight may be expected, as one day:
Overtime = TimeValue(CDate(1 + DurationEnd - ShiftEnd))
The "magic" here is due to the nature of data type Date around numeric zero:
MS Access Can Handle Millisecond Time Values--Really : Page 2
Notice the graph: Firgure 1.
Overtime will be counted in days. To obtain an hour value, multiply by 24.

Related

How do I tell google sheets to only make a calculation after a certain time period?

Context
So I am currently building a database of data for financial assets to conduct some machine learning from to build trading signals. I am trying to calculate the geometric mean but over a given period (monthly). I want to tell google sheets to only calculate the geometric mean after every month. I tried using this formula to no avail:
=IF(last date of the month - first date of month = total days in a month,
GEOMEAN(filter(abs(range),abs(range)>0)),""))
** There were values in the last date of the month - first date of month = total days in a month **
It ended up doing it for every day for the 10 year data set.
** Update
This is the data:
Date Close Cleaned Data Returns Gross returns Geometric average returns
13/11/2015 280 -0.0267 0 1
16/11/2015 280 -0.0267 0 1
17/11/2015 280 -0.0267 0 1
...
23/12/2016 296.4 0.0236 -0.1561348935 0.8438651065
28/12/2016 295.2 0.0199 -0.0770931339 0.9229068661
29/12/2016 294.7 0.0183 0.03341318035 1.03341318
30/12/2016 294.9 0.0190 0.3718276303 1.37182763
Problem (UPDATE)
How do I create a function to let google sheet do calculations only for the last day of every month for a given time series data? Say within this time period, (1 year) I want to calculate the geometric mean for each month in this period and for new data I might want to add later in the future.
To do this you will have to set a trigger event. This is found within the script editor under the edit tab, second to last option.
Image of where to find the trigger manager: It's in spanish, but it will be found in the same place
Once there, click on add trigger, which will be found on the bottom right corner. The first option will ask you which function do you want to run from the bound script. Then select the source of the event and select according to time (My platform is in spanish so I'm trasnlating it you might have it written differently). Then it will prompt you: if you want it to be at an exact date and time, every minute, every hour, day, week and month. Select month and select the day of the month you want the trigger to happen in the next prompt and select the time for the last prompt, then click save.
Finding the last day of a month:
function lastdayOfMonths() {
let html='';
let td=new Date();
for(var i=0;i<12;i++) {
let dt=new Date(td.getFullYear(),td.getMonth()+i+1,0);
let dts=Utilities.formatDate(dt, Session.getScriptTimeZone(),"E MMM dd,yyyy");
html+=Utilities.formatString('<br />%s',dts);
}
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html), "Last Days of Months for next year");
}

Interesting SSRS parameter discovery when using subscriptions

I have recently been putting together an SSRS report that will run every 15 minutes for the previous 15 minute 'chunk' of time. In essence a very straight forward and simple report that will run via an automated subscription.
I was using Microsoft SQL Server 12 Report Builder Version 3.
I was alerted to an issue with the output csv when my recipient reported being sent blank files, most odd considering the report generated as expected when run manually.
Long story short, it was the expressions I was using to generate the From and To dates. Manual runs produced data, subscription runs did not.
Original parameters
FromDate
dateadd(DateInterval.Second, (second(now()) + 900) * -1, dateadd(Dateinterval.Minute, (minute(now()) mod 15) * -1, now()))
ToDate
dateadd(DateInterval.Second, (second(now()) + 1) * -1, dateadd(Dateinterval.Minute, (minute(now()) mod 15) * -1, now()))
New Parameters
FromDate
dateadd(DateInterval.Minute, -15, dateadd(DateInterval.Minute, cint(datediff(DateInterval.Minute,today(),now()) / 15) * 15, today()))
ToDate
dateadd(DateInterval.Second, 899,Parameters!FromDate.Value)
Thought I would post this here for two reasons
Theories as to why
It might help someone in the future
Your original parameters take Now and subtract the minutes to arrive at a 15-minutes time, then they take the seconds of another Now (which is later and could be in the next second or even minute) and subtract that value to arrive at a 0-second time (or a 59-second time). This could already cause a problem when there is a change of seconds between the first and the second Now, which isn't very unikely, as on my test system there were 0.59 seconds between the two evaluations of Now in the FromDate parameter. Also, the Now value is more accurate than just a second, and your formula does not respect that. Therefore, if the records you are trying to process in your report happen to have a time of exactly a quarter of an hour, the first parameter is for sure greater (by maybe 0.01 second) and so the record is ignored.
Your formula for the "new parameters" does not depend on the seconds of Now() and will always return a time with no fraction of a second, so I guess that that's what makes the difference.
The expression for the FromDate could be simplified a little:
=Today.AddSeconds(900*(DateDiff(DateInterval.Minute, Today, Now)\15-1))
If you do not plan to run the report very short before midnight, there should not be a problem caused by a change of the day during the evaluation of Today and Now, and you could calculate the second parameter in a similar way, independently from the first one:
=Today.AddSeconds(900*(DateDiff(DateInterval.Minute, Today, Now)\15)-1)
The original parameter values were being calculated individually which means they would each have slightly different values for Now(). I know this is a long shot, but it's a theory. If the subscription job fired off a fraction of a second before a 15 minute interval, it's possible that the ToDate returned just before the FromDate. This would result in an invalid date range.
With the new expressions, the ToDate is referencing the FromDate which forces them to be calculated in sequence, not in parallel. Not to mention you're adding to the FromDate which also forces the date range to have a consistent length. However, you may still run into a case where you get the same report twice if the FromDate is calculated on the wrong side of a 15 minute cutoff.
One way to test/avoid this issue would be to offset the subscription time so that it doesn't actually try to fire at the exact 15 minute cutoffs. For example, you could have it scheduled to go off 1 minute afterwards.

Rails DateTime helper logic

Quick question. I am using the distance_of_time_in_words helper to check how many days an object was created. This works fine but I dont want it to have to go 24 hrs before it counts a day but want it to count "1" day once it is "00:00"
eg distance_of_time_in_words("2016-08-11 11:00", "2016-08-12 00:00") should be 1 day but it is 13 hrs
I want that once it passes "00:00" it should count as a 1 day?
You may be able to use
time_ago_in_words(date_item_was_created.at_midnight)
time_ago_in_words allows you to forgo adding the 'now' time* and by moving the created-at date back to midnight, you'll cross the one-day mark
at the next midnight. According to the API doc, it should give you 'round' days for anything over a day, which sounds like what you're after.
*You can continue to use distance_of_time_in_words if you're not comparing to the current time.
This is what you meant I guess.
def distance_of_time_in_words(time1,time2)
d1 = Time.parse(time1.to_s).to_date.strftime("%d").to_i
d2 = Time.parse(time2.to_s).to_date.strftime("%d").to_i
seconds = Time.parse(time2.to_s)- Time.parse(time1.to_s)
hours = seconds/3600
if d2-d1 >= 1
return "#{(d2-d1).to_s} days"
else
return "#{hours.to_s} hours"
end
end

I am getting a negative time when I try to calculate a night shift.

I need time worked to do some other calculations and the times are all coming back negative if they worked an over night. Here is my formula that I am using to calculate time worked. (([EndTime]-[StartTime])*24*60) As long as they complete their shift in the same day, the calculation works fine but, if they work 6am to 6 pm, I get a total shift time of -720. All of my calculations are in minutes by the way. Does anyone know how to make the negative time show correctly? Thanks!
You can use this expression:
Minutes = (1 + EndTime - StartTime) * 24 * 60 Mod 24 * 60
For your example, values would be:
Minutes = (1 + #6:00# - #18:00#) * 24 * 60 Mod 24 * 60
This is an old trick based on the fact that the Date data type has an "undocumentated window" between but not including the numeric values 0 and -1.
Thus, the limitation is that it will only work for durations less that 24 hours.
You can use this formula:
Datediff("n", StartTime, EndTime)
Where "n" says you want the difference in time between those dates as minutes.
If you still get negative numbers after this then I suspect you are not storing the date and time together (you should be).

How can I tell how many minutes have passed between Now() and 7am that day?

Basically I just need to know how much time has passed from a certain time that day till Now() this will be run on a timer throughout the day and used to determine when something should be run (this might seem odd but there is logic behind it).
The issue with the code below is that it gives me a very high negative number. I can only assume that this is caused from the TimeSerial not actually containing a date and only the time so it throws everything off.
Can anyone point me in the direction of a way to do what I want? I am certain that the answer is something super simple that I am missing but I haven't been able to find it.
DateDiff("n",Now(),TimeSerial(07,0,0))
You want the number of minutes from 7 AM until now. Your DateDiff had those two swapped around and that's why you got a negative value.
The reason the magnitude of that number was so large is you were asking for the difference between 07:00 on Dec 30 1899 and today. This is what that TimeSerial expression gives you ...
? Format(TimeSerial(07,0,0), "mmm d yyyy, hh:nn:ss")
Dec 30 1899, 07:00:00
I think this is what you want instead ...
DateDiff("n", Date + #07:00#, Now)