Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9159229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:26:28+00:00 2026-06-17T13:26:28+00:00

Apologies for yet another date/time related post. I haven’t got my head around this

  • 0

Apologies for yet another date/time related post. I haven’t got my head around this yet, so any comments welcome. Executive summary: Excel can be used to work with small elapsed times (athletic event times, and so on), but Sheets can’t, because you need to write a script to display small times, and the script screws something up so that Sheets no longer treats the cell as a time when the time is later manually changed.

The times I need are normally short, in the region of a couple of minutes, with seconds to 2 decimal places. I have to do arithmetic on these times (normally only comparisons to another time).

We currently store everything in Excel, which works fine. If you define a custom display format in a range, and then enter times as something like 2:43.02 (2 mins, 43.02s), then the cell still contains a time, and Excel can do arithmetic on those times.

I then upload the Excel spreadsheet, and open it in Sheets. There is no built-in formatting extension, as there is in Excel, so I have to use an extension function to display the time as 2:43.02, for example (see below; the function calls setNumberFormat). In the new Sheets version of the document, Excel times are still times, and comparison works, and everything looks right.

Here’s the problem. Everything only works until you manually enter a new time into a Sheets cell. If I enter 2:41.05, for example, the cell no longer contains a time object, and all arithmetic is broken. So, I can’t use Sheets to replace Excel. I have to keep everything in Excel and upload it occasionally, keeping the Sheets version as read-only.

There’s some magic in Sheets which determines whether a cell contains a date or not. If I use a built-in time format, then Sheets knows it’s a time, and can do arithmetic if the time is manually changed. If I change the time format using the function below (from here), then that magic is lost, and I can’t manually change the time.

function EditFormat() {
  var oldname = SpreadsheetApp.getActiveRange().getNumberFormat();
  var name = Browser.inputBox("Current format (blank = no change):\r\n"+ oldname);
  SpreadsheetApp.getActiveRange().setNumberFormat((name=="")?oldname:name);
}

Question: is setNumberFormat broken? Is there a better way to do all this? Can I do something else in the script which retains the cell’s magic status as a time? Or do I have to go back to Excel?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:26:29+00:00Added an answer on June 17, 2026 at 1:26 pm

    This is due to a (sadly long-standing) Sheets bug whereby the parser fails in two respects:

    1. The format 2:43.02 is not successfully coerced into a time value, but the format 0:02:43.02 (or 0:2:43.02) is.
    2. Even so, the hundredths of seconds are ignored for directly entered values.

    Both points apply for all values in the spreadsheet, however only point two applies for directly entered values. So a workaround is to enter via a formula:

    =VALUE("0:2:43.02")

    or you could have an input column that is formatted as plain text, and then have a display column that similarly converts to a time value via formula (and this display column would be custom formatted). Or, you could have a helper script that presents an input box for the active cell, where you enter the split time, and then creates a formula like above and populates it in the cell (the set number format could be built in to this script as well).

    I wish these workarounds were unnecessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yet another reason why I hate IE for being different. I've got this code:
Apologies if this question is a bit obscure, I've been banging my head against
Apologies for posting yet another Java jar question. I did have a look at
To begin with, let me apologise for asking yet another question referring this topic.
First of all, I apologize for yet another interface question. I thought that this
Apologies if this has been answered already but I have yet been unable to
This is my first post here so apologies if the setup is kind of
Apologies if this has been answered elsewhere, but I have yet to find a
I apologize for yet, another beginner question. I have a .Net background and this
Apologies if this is a duplicate, 20 minutes of searching didn't yield this exact

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.