converting timestamp from descending to new/different ascending value in excel - sorting

I have the values of the first half of a college basketball game counting down from 20 minutes. I need to match the times that I have with the times on a DVD where the times are different ascending from a value at 40:36 minutes.
The basketball game counts down from 20 minutes (the tip-off) whereas the time on the DVD goes up from 40:36 minutes (the tip-off on the DVD). It would save me hours and hours of work if I could somehow automate this process. I did the below manually. Any ideas?
Values I Have = Values I Need: (starting from 40:36 ascending up)
20:00 = 40:36
19:40 = 40:56
19:40 = 40:56
19:11 = 41:25
19:10 = 41:26
18:56 = 41:40
18:40 = 41:56
18:13 = 42:23

Using this formula solved my issues described above.
=LEFT(CONCATENATE("00:",TEXT(A18,"hh:mm:ss")),8)

=(B1-A5)+B2
B1 = Time in Quarter
A5 = Game time
B2 = Start of DVD time (0:40:36)
e.g.:
Time in Quarter 0:20:00
Start time on DVD 0:46:36
Game time DVD time
0:19:40 =(B1-A5)+B2
Make sure you have the times are stored in the following format: 12:20:00 AM for 20:00 so that excel can do the time arithmetic correctly. You can format the cells to h:mm:ss if you want.

Wow, amazing. You guys really saved me a lot of work here!
=($B$1-A5)+$B$2 is all I needed!
Using Luke's formula while anchoring the B column values is exactly what I needed.
Guys, I can't tell you how much I appreciate your help. Thank you both!!! :)

Related

Simple algorithm to alternate days

I need to alternate between 2 tasks every day, and I need a simple algorithm to know which task I need to do.
I need to be able to run this algorithm by head, using simple general knowledge (like day of week, day of month, etc), and it must not rely of which task has been done the previous day (because I have a crappy memory).
I have tried checking for parity in a combination of day of week / day of month / # of month, etc, but couldn't find a suitable system: day of week have 2 consecutive odd numbers, same goes for day of month every so often.
I am afraid that this is impossible: if you can't remember what you did the day before, any other procedure will require more mnemonic effort.
remember what you did on January first (or another date),
remember the parities of the cumulated months: oeoeoeooeoe or ooeoeoeeoeo for a leap year,
add the cumulated parity of the month before* to the parity of the day,
add that to the parity of the first task.
E.g. if A on January 1st 2022, then on March 17, 2022: e + o = o gives B.
*In January, use even.
You can also state the month parity rule as: until August inclusive, use the co-parity of the month number; then use the parity. But for a leap year, change that parity after February (excluded).
I need to be able to run this algorithm by head
So, you don't need to take help of Computer science. You can use cognitive human ability to map a thing to another thing.
Note: This need not make sense to everybody though, if you are thinking out of the box.
Map task 1 as God's day.
Map task 2 as Devil's day in your brain.
This should be simple just like day and night.
Now, remember that devil's evil karma is always burnt by God the next day and that devil never learns his lesson. So this way, alternating would be easy.
Friends Episode snippet on Youtube
Just count the number of days in between your date and a given "zero" one...then use parity.
Take number of seconds (or milli, or whatever) since EPOCH (common zero for date and time), divide (integer division) by 60x60x24 (or 1000x60x60x24, or what is appropriate), you then get the number of days since EPOCH.
----EDIT----
Example: Got 1653910695 seconds since EPOCH (at the time of my experience). Dividing it by 60x60x24 give 19142 days. To morrow it will give 19143, etc.
<?php
$day = Date('j');
$previous_day = date('j', strtotime("-1 days"));
if($day%2==0 OR $previous_day%2!=0)
echo "Task 1";
}else{
echo "Task 2";
}
?>

Summing times in Google sheets

I have a sheet where I record my working hours (this is more for me to remind me to stop working than anything else). For every day, I have three possible shifts - early, normal & late, and I have a formula which will sum up any times put into these columns and give me the daily total hours.
To summarise the duration of time spent working in a day, I use the following formula: =(C41-B41)+(E41-D41)+12+(G41-F41) which is:
early end time minus early start time
normal end time minus normal start time PLUS 12 hours
late end time minus late start time
Which gives me output like this:
What I cannot seem to achieve is, the ability to sum the daily totals into something which shows me the total hours worked over 1-week. If I attempt to sum the daily totals together for the example image shown, I get some wild figure such as 1487:25:00 when formatting as 'Duration' or 23:25:00 when formatted as 'Time'!
All my cells where I record the hours worked are formatted as 'Time'
When using arithmetic operations on date values in Google Sheets, it's important to remember that the internal representation of a date is numeric, and understood as the number of days since January 1, 1970.
What follows from that, is that if you want to add 12 hours to a time duration, you should not write "+12" because that will in fact add 12 days. Instead add "+12/24". In other words, try the following formula instead of the one you are using now:
=(C41-B41)+(E41-D41)+(12/24+G41-F41)

Unknown timestamp reference date

I'm currently dealing with a system which uses an unknown timestamp mechanism.
The system is running on a Windows machine, so my first thought was that it uses some kind of Windows epoch for its timestamps, but it appears it does not.
My goal is to convert these timestamps to Unix timestamps.
A few examples:
The following timestamp: 2111441659 converts to: 2013-10-01 11:59
2111441998 to 2013-10-01 17:14
2111443876 to 2013-10-02 14:36
2111444089 to 2013-10-02 17:57
(All dates are GMT+2)
I've tried to calculate the reference date using the data above, but somehow I get a different result with every single timestamp.
Could anybody shed some light on this rather odd problem?
Thanks in advance!
To me the number seems to small to be milliseconds. My first guess was then seconds but looking at the speed this number varies with i think minutes is a better guess. Doing some math on it 2111441659/60/24/365 = 4017.20254756 which suggests the epoch might be sometime in the year -2000?
Here is a list of common epochs in computing but the year -2000 is not really there :) How are you obtaining this timestamp?
P.S. are you sure the year is set to 2013 on this machine and not to 4013? :) This would then fit with the .NET epoch of January 1, Year 1
In order to distinguish your timestamp from Unix timestamp, let's call yours The Counter.
So we have four counter values with their corresponding DateTime value. The first thing to do is calculate the counter's unit correspondence to a real time unit, let's say a second.
In order to do that, we need (1) the difference d between two counter values and (2) the difference s between their corresponding DateTimes, in seconds.
Considering the first two values we have d1=2111441998-2111441659=339. The difference between 2013-10-01 11:59 and 2013-10-01 17:14 (in seconds) is s1=18900. Consequently, the counter's unit corresponds to u1=s1/d1=55.7522123894 seconds.
But if we do the same with pairs #2 and #3, we will find that u2=40.9584664536 seconds.
Similarily, pairs #3 and #4 give us u3=56.6197183114 seconds.
My conclusion therefore, is that there's no alignment between the counter values and the corresponding DateTimes provided. That's the reason why you get a different result with each sample.
Finally, after many hours of comparing the timestamps with the datetimes, trying to discover the logic between them, I've found the answer by reverse engineering the software which generates the timestamps.
It turns out that the integer timestamps are actually bitwise representations* of the datetimes.
In pseudocode:
year = TimeStamp >> 20;
month = (TimeStamp >> 16) & 15;
day = (TimeStamp >> 11) & 31;
hour = (TimeStamp >> 6) & 31;
minute = TimeStamp & 63;
*I'm not sure if this is the correct term for it, if not, please correct me.

How can I keep backup of last 1 year with only 100 backup copies, assuming backup runs every day?

Assuming that I create a backup copy everyday and assuming that each backup is a single compressed file and contains the timestamp information in its filename.
Now, I want to write a daily running script that deletes older backups and keeps only 100 backups. However these 100 backups are spread over 1 year such that I still have a 1 year old copy, however I should have more copies of recent backups and lesser copies of older backups, i.e., at any given moment, the distance between two surviving consecutive backup copies keeps increasing as we go back in time.
Algorithm should also take the fact into account that it will be running once daily.
Also, is there a name for such algorithm - exponential range?, exponential distance?, non-linear backup expiry?, logarithmic something? anything?
If you're including code in your answer, I'd prefer Ruby (but not necessary, as I can manually transcompile it to Ruby if it is in another language).
It sounds like you're thinking about something like the Tower of Hanoi. Tape backup systems sometimes use this as a way to manage backup tapes. The Wikipedia article has several algorithms. It's often used as a programming exercise when you're learning recursion.
The game is based on moving a stack of different sized disks from one peg to another without ever putting a bigger disk on top of a smaller one. If you had five sets of tapes, labelled A through E, you'd end up moving them like this.
ABA
CABA
DABACABA
EABACABADABACABA
The set used least often is E, so if you start with E on January 1, you'll end up like this.
E Jan 1
ABA Jan 2-4
CABA Jan 5-8
DABACABA Jan 9-16
EABACABADABACABA Jan 17-Feb 1
The E set will be overwritten on Jan 17. Coverage will look like this on Jan 16.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
E D C B A
A ruby program that solves the Tower of Hanoi puzzle
Let me describe a very simple algorithm that might work for you.
First of all assign everyday a global date counter, say number of days after Christ. You wanted ruby, so I show you how to do that in ruby (this shows that today is 734918th day)
require "Date"
Date.today - Date.new(0)
Now let me tell you which files you keep: You keep all files from the last 30 days, for the next 40 you keep every file with index divisible by 2, for the next 80 you keep every day with index divisible by 4, for the next 120 you keep every file with index divisible by 8 and for the rest 85/86 you keep every file with index divisible by 16. Thus as time moves on all you will need will be to check if you need to remove some of the stored files and will never need to show a file you already erased. Tell me if you need code for this logic, too.
Keeping everything from the last two months and every sunday backup from the last year would result in a little over 100 files. Easy to explain, easy to execute and you know beforehand if a backup is there or not.
Untested:
require 'date'
def bup_name(date=Date.today)
"#{date.to_s}.bup"
end
def delete(fname)
#todo: exception handling
File.delete(fname) if File.exist?(fname)
end
today = Date.today
# make backup bupname(today)
delete( bup_name( today << 12 ))
two_months_ago = today << 2
delete( bup_name( two_months_ago )) unless two_months_ago.sunday?

How can I do time/hours arithmetic in Google Spreadsheet?

How do I do time/hour arithmetic in a Google spreadsheet?
I have a value that is time (e.g., 36:00:00) and I want to divide it by another time (e.g., 3:00:00) and get 12. If I divide just one by the other, I get 288:00:00 when what I want is 12 (or 12:00:00).
Note that using the hours() function doesn't work, because 36:00:00 becomes 12.
When the number being returned by your formula is being formatted as a time, and you want it formatted as a plain number, change the format of the cell to a plain number format: click the cell and then click Format, Number, Normal.
Time values in Google spreadsheet are represented as days and parts of days. For example, 36:00:00 is the formatted representation of the number 1.5 (a day and a half).
Suppose you divide 36:00:00 by 3:00:00, as in your example. Google Spreadsheet performs the calculation 1.5 divided by 0.125, which is 12. The result tells you that you have 12 3-hour intervals in a 36-hour time period. 12, of course, is not a time interval. It is a unitless quantity.
Going the other way, it is possible to format any number as a time. If you format 12 as a time, it's reasonable to expect that you will get 288:00:00. 12 days contain 288 hours.
Google Sheets now have a duration formatting option. Select: Format -> Number -> Duration.
Example of calculating time:
work-start work-stop lunchbreak effective time
07:30:00 17:00:00 1.5 8 [=((A2-A1)*24)-A3]
If you subtract one time value from another the result you get will represent the fraction of 24 hours, so if you multiply the result with 24 you get the value represented in hours.
In other words: the operation is mutiply, but the meaning is to change the format of the number (from days to hours).
You can use the function TIME(h,m,s) of google spreadsheet. If you want to add times to each other (or other arithmetic operations), you can specify either a cell, or a call to TIME, for each input of the formula.
For example:
B3 = 10:45
C3 = 20 (minutes)
D3 = 15 (minutes)
E3 = 8 (hours)
F3 = B3+time(E3,C3+D3,0) equals 19:20
I had a similar issue and i just fixed it for now
format each of the cell to time
format the total cell (sum of all the time) to Duration
I used the TO_PURE_NUMBER() function and it worked.
So much simpler: look at this
B2: 23:00
C2: 1:37
D2: = C2 - B2 + ( B2 > C2 )
Why it works, time is a fraction of a day, the comparison B2>C2
returns True (1) or False (0), if true 1 day (24 hours) is added.
http://www.excelforum.com/excel-general/471757-calculating-time-difference-over-midnight.html
if you have duration in h:mm, the actual value stored in that cell is the time converted to a real number, divided by 24 hours per day.
ex: 6:45 or 6 hours 45 minutes is 6.75 hours 6.75 hours / 24 = 0.28125 (in other words 6hrs45minutes is 28.125% of a day). If you use a column to convert your durations into actual numbers (in example, converting 6:45 into 0.28125) then you can do you multiplication or division and get the correct answer.
In the case you want to format it within a formula (for example, if you are concatenating strings and values), the aforementioned format option of Google is not available, but you can use the TEXT formula:
=TEXT(B1-C1,"HH:MM:SS")
Therefore, for the questioned example, with concatenation:
="The number of " & TEXT(B1,"HH") & " hour slots in " & TEXT(C1,"HH") _
& " is " & TEXT(C1/B1,"HH")
Cheers
In an fresh spreadsheet with 36:00:00 entered in A1 and 3:00:00 entered in B1 then:
=A1/B1
say in C1 returns 12.
Type the values in single cells, because google spreadsheet cant handle duration formats at all, in any way shape or form. Or you have to learn to make scripts and graduate as a chopper pilot. that is also a option.

Resources