Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
How to calculate elapsed time in military time using apps script
Post Flair (click to view more posts with a particular flair)
Post Body

Hi all,

I am trying to get apps script to work out the amount of elapsed time, but it's throwing up really strange numbers and I can't figure out why.

What I am trying to do is to take a start time and end time (in military time) on Sheet A, have it work out the actual amount of time between start and end in hours and minutes, and enter that on Sheet B.

On Sheet A, the cells in question are formatted to show the value in it as time, and so they read as ##:##:## (I don't really want the seconds there, but the format doesn't give me the option for just hours and minutes...)

What I have tried is:

var anaestheticStart = anaestheticSheet.getRange("P29").getValue();

var anaestheticEnd = anaestheticSheet.getRange("P28").getValue();

var anaestheticTime =(anaestheticEnd-anaestheticStart);

and to enter the value of anaestheticTime into the next available row in column 21 of Sheet B:

surgeryLog.getRange(nextRowSurgeryLog, 21).setValue(anaestheticTime);

The value of P28 is currently 09:10

The value of P29 is currently 10:25

10:25-09:10 should be 01:15, but the cell keeps returning a value of -4500000

Any searches I've done have just turned up examples of building time cards with AM and PM, and those mostly use the built-in formulas in Sheets instead of Apps Script.

Can someone tell me what I'm doing wrong?

Many thanks to the wonderful people in here with the patience to hold us newbie's hands!

Author
Account Strength
80%
Account Age
6 years
Verified Email
No
Verified Flair
No
Total Karma
7,588
Link Karma
599
Comment Karma
6,919
Profile updated: 3 days ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago