## Recommended Posts

I found myself often converting hours & minutes to a decimal format when creating invoices. This workflow simply does that calculation and copies it to the clipboard. Type in the keyword, then hours:minutes to get that amount of time in decimal (rounded to the nearest hundredth).

For example, 6 hours and 38 minutes:

dtime 6:38

Copies 6.63 to clipboard.

http://static.etling.com/assets/decimal_time_workflow.zip

Is there another copy of this workflow around? I am looking for this specific function and am having no luck

Try this in a Run Script box with language as python and input as {query}.  You can pipe it out to a Copy to Clipboard action.

```i = "{query}".split(":")

m=int(i)+(int(i)*60)

print float(m)/60```
Edited by dfay

Also if you want to go further here is a whole command-line time calculator library I wrote in python some years ago.  The code above does the conversion to minutes rather than seconds but it's basically the same as the input_time, to_seconds and base_time functionality below.

```def to_seconds(i):
seconds=int(i)+(int(i)*60)+(int(i) * 60 * 60)
return seconds

def from_seconds(raw_seconds):
seconds=abs(int(raw_seconds))
minutes=0
hours=0
while seconds > 59:
seconds=seconds-60
minutes=minutes+1
while minutes > 59:
minutes=minutes-60
hours=hours+1
if raw_seconds<0:
hours=hours*-1
return [str(hours), str(minutes), str(seconds)]

def input_time():
time = raw_input('enter time in h:m:s format: ')
time_list=time.split(":")
return time_list

increase=input_time()
return(from_seconds(to_seconds(base_time)+to_seconds(increase)))

def subtract(base_time):
decrease=input_time()
return(from_seconds(to_seconds(base_time)-to_seconds(decrease)))

def multiply(base_time, multiplier):
return(from_seconds(to_seconds(base_time)*multiplier))

def divide(base_time, divisor):
return(from_seconds(to_seconds(base_time)/divisor))

def milePaceToKMPace(mile_pace):
return(multiply(mile_pace,0.621371))

def kmPacetoMilePace(km_pace):
return(multiply(km_pace,1.609343994))

def decimal_equivalent(base_time):
return(to_seconds(base_time)/3600.0)

def negative(base_time):
return(multiply(base_time,-1))

def display_time(i):
if len (i)==1:
i="0"+i
if len (i)==1:
i="0"+i
print i+":"+i+":"+i```

Edited by dfay

On 2/16/2017 at 11:28 AM, dfay said:

Try this in a Run Script box with language as python and input as {query}.  You can pipe it out to a Copy to Clipboard action.

```
i = "{query}".split(":")

m=int(i)+(int(i)*60)

print float(m)/60```

I got this to work and thank you so much, I was sad when the file here was a dead link. Can you explain how to make a script that will go the other way? hundereths to hh:m

Thank you soooooo much!!!!

Based on what dfay provided code wise I made this if anyone wants to use or modify it.

It could use some cleaning of the decimal places it outputs, etc but is functional.

Edited by alwaysaugust

FWIW, you should never use : in a filename that's intended for a Mac. The old macOS used : as a path separator, not /, so using a colon in a filename can cause unexpected behaviour.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.