GSheets: Calculating difference in times in a 24 hour business - google-sheets

I'm trying to calculate the difference between a start time and a persons first action and the same for the end time and their last action.
My problem is due to having a 24 hour business I can't seem to figure out a single formula to cope with shift times and actions being anywhere in the 24 hour time frame.
Example sheet
The start times are manually imputed as "06:00" format and the Actions are taken from a Left("12/09/2017 19:08:25"),8 format.

The data entry is bad. You need to enter start and end times with its date ( You could just format it as just time for presentation purposes). But dates have to entered in and should be there below the time. For example, One of the finish times is 00:00:00 , while the expected finish time is 23:00:00. We could assume that he worked one hour late and ended his shift by start of tomorrow. But spreadsheets cannot assume. It would think that he finished by today morning 00:00:00 instead of his actual finish time tomorrow morning 00:00:00. So he went off early by 23 hours. Once that's fixed, You could simply find the difference between the two times. But, You have to format that column as number>Duration instead of Time.
To sum up,
Add dates to start and end times
Format the resulting difference column as Number>Duration.

Related

Conditional Formatting Time After Midnight in Google Sheets

I'm working on a Google Sheets timesheet. I want to conditionally format a cell if the user enters a Time Out past Midnight. In the example below, the user added an extra 15 minutes to his Time Out, which belongs on the row for the next day.
timesheet
I tried Conditionally Formatting a cell for any time greater than Midnight, which didn't work because ALL times are beyond Midnight. Also, I want to apply the conditional formatting to every cell in my Time Out columns. So I'm guessing the solution must involve the ARRAY function.
Any suggestions? Thanks in advance!
Assuming you mean that you need to highlight those timelines that start in one day and finish in the next one, you can think that the condition will be true if the hour of leaving is smaller than the hour of arriving (unless you can have more than 24 hours straight, in which case this wouldn't work).
Then you could set this condition:
=if(hour($C2)<hour($B2),true,false)

Time format in Google sheets

I have a 2 columns. One with a planned time of departure and another with actual time of departure. Up until a few days ago, if there was a delay, the difference would read as a negative number. For example, if the planned time was 8:00AM and the actual time was 8:21AM, the 3rd column showed a delay as "-00:21:00"), but now the duration of the delay is displayed as 24:00:00 minus the number of minutes of the delay, as shown in this snippet:
Fortunately, any/all formulas still read and process the values, so this is really just a cosmetic issue for anyone who wants to glance at the raw data.
sounds like the formatting got reset. select your Delayed column and change the format to Duration

How to Link custom week numbers with an existing time tree graph up to minutes in Neo4J?

I already have a graph (time tree) that contains Year, Month, Day, Hour and Minutes. It is something like that of what Mark Needham shows in his blog link but it goes until Minutes instead of days. So the link looks something like this :
2017-[:HAS_MONTH]-2-[:HAS_DAY]-25-[:HAS_HOUR]-16-[:HAS_MINUTE]-45
I also have Year to week number relation. The starting and ending dates of the Workweek are custom. For eg my week 2 in 2017 starts from 2017-01-05 19:00 (yyyy-mm-dd hh:mm) and ends on 2017-01-12 18:59. I have all the nodes between those 2 dates in my time tree but I am not able link them to week 2 node. Is there a way to do this? I am not using graphaware. I managed to do something for this one week by collecting all the days from 5th to 12th and then removing the hours 0 to 18 from 5th and 20th to 23rd on 12. But I need to do this for a couple of years and this method may be very cumbersome. Is there a better way for this?
You can use apoc plugin already :)
apoc.date.format uses JAVA simpledateformat under the hood I think. Looking at http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html this is already possible. But you have to first parse it into unix and then back.
with "2017-01-05 19:00" as date
with apoc.date.parse(date,"s","yyyy-MM-dd HH:mm") as unix
return apoc.date.format(unix,"s","yyyy ww")

Timezone aware postgres query create a timeseries for minutes, hours, days

I am having a hard time to figure out how to deal with the following problem:
Our company is publishing posts to social media platforms. Those posts are stored within the database once they where successfully postet.
We want to provide a dashboard showing an overview of how many posts the user published over a time period grouped by minutes, hours and days.
I want to display the results as a time series graph.
This would work fine, but it gets very tricky once I have to support multiple time zones when I do aggregation/grouping by days. (apparently posts around midnight belong to different days depending on which time zone you are)
My current solution builds the postgres query using rails ActiveRecord. The problem I am facing is that I am struggling to deal with the timezone conversions...
Also I am not particular good at postgres...
The current implementation essentially looks like this (I removed irrelevant code):
Publication.select(
%{date_trunc('#{interval}',
published_at::timestamptz at time zone interval '#{time_zone_offset}')::timestamptz as time,
count(published_at)})
.where(%(published_at BETWEEN
timestamptz '#{start_date}' AND
timestamptz '#{end_date}'))
.group("1")
.order('time').limit(LIMIT)
For example:
I have one publication at 2016-03-15 10:19:24.219258 (Thats how it is stored inside the database therefore UTC time)
I create the following query:
SELECT date_trunc('hour',
published_at::timestamptz at time zone interval '+01:00')::timestamptz as time,
count(published_at) FROM "publications" WHERE (published_at BETWEEN
timestamptz '2016-03-15 10:00:00 +0100' AND
timestamptz '2016-03-15 12:00:00 +0100') GROUP BY 1
;
Which results in:
time | count
------------------------+-------
2016-03-15 10:00:00+01 | 1
(1 row)
Which should be:
time: "2016-03-15 10:00:00 UTC" or "2016-03-15 11:00:00+01" ( i don't care about the time zone representation but this is simply the wrong result)
Anybody knows what I am doing wrong here?
The main problem I got stuck is that I want to be able to group/aggregate publications per day, with respect to the time zone of the user requesting the query.
I don't care which time zone is returned as the front end can transform it to the user time zone.
Any feedback, help, or answer is highly appreciated.
Many thanks
Thanks to the discussion I had with devanand one solution is to split up the code and handle the daily interval with the query used in the question.
For the other intervals I use the following query:
Publication.select(
%{date_trunc('#{interval}',
published_at::timestamptz) as time,
count(published_at)})
.where(%(published_at BETWEEN
timestamptz '#{start_date}' AND
timestamptz '#{end_date}'))
.group('1')
.order('time').limit(LIMIT)
I am not happy with the solution though as it feels more like a workaround to me

Get difference of time and output to decimal format

I am trying to get the different between two times, lets say 2:00PM and 12:00AM. So I want to get how many hours are between those two times but have it be in decimal format which in this case would be 10.00 hours?. I am not sure how to go about this. The most I got to was just subtracting the two times and multiplying that decimal number by 24 which works if I do 2PM and 11PM which gives me 9.00hours, but as soon as I go to 2PM and 12AM it should show 10.00hours but shows -14.
Assuming your times are in ColumnA ("earlier") and ColumnB ("later") then:
=if(B1=0,(B1-A1+1)*24,(B1-A1)*24)
should work for you. The quotes are because (seems to depend upon how the times values are entered) Google may associate a date with the times even when that is not displayed. Google treats noon as 12:00PM which is wrong, it is noon not after noon (post meridiem) but one minute later 12:01PM, etc, does make sense. So 12:00AM is midnight and a special case where a date is associated because seen as midnight of the previous day - it counts as 0 not 24. Hence relative to 2pm today is 14 hours earlier (your result) whereas midnight tonight is 10 ahead (the result you expected).
The formula above checks whether the later time is midnight and compensates for that being treated as the day before by +1 in the formula.

Resources