Alpha Video Training
Results 1 to 5 of 5

Thread: Subtracting 2 entered times

  1. #1
    Member
    Real Name
    Gary Coslop
    Join Date
    Sep 2019
    Posts
    32

    Default Subtracting 2 entered times

    I know this question has been asked before, and I have looked through many of the answers trying to incorporate them, however it does not seem to work for me, and I was hoping someone could guide me on it.

    I have a timefrom and timeto textbox field that I have tried both on the detail view in grid and in a ux component. These two have been tried both as character and as time fields. I then have a units field that is numeric. Under Client-Side Properties for the units field, I enter timeto-timefrom (when the respective cells are set to time) and TOTIME(TOSECONDS(timeto)-TOSECONDS(timefrom),1,0) when they are set to character.

    In either case, I then set the HTML5 type to time. I have tried setting the display format to time("0h:0m:0s am",<value>) however I either get a 0 or a NaN in the Units field. I figure there has to be something I am missing.

    Alpha 4.6.1.2 Build 6012.

  2. #2
    "Certified" Alphaholic
    Real Name
    Larry Grupido
    Join Date
    May 2010
    Posts
    1,826

    Default Re: Subtracting 2 entered times

    You want to know the number of seconds between two time values that have been entered as hh:mm:ss AMPM

    Assuming they are on the same day and that from time comes before to time?

  3. #3
    Member
    Real Name
    Gary Coslop
    Join Date
    Sep 2019
    Posts
    32

    Default Re: Subtracting 2 entered times

    seconds is fine. Ultimately I need the quantity of 15 minute units, but I can make the math happen if I can get any result. Even the difference in seconds. In my application, they will always be on the same day, and if by some fluke they cross midnight, it won't be by much, so I can work the math "if negative number..." I ended up writing a whole bunch of JS code to make it work. I got it working, but this should be such a common and basic task. I feel like I took the long way around it.

  4. #4
    "Certified" Alphaholic
    Real Name
    Larry Grupido
    Join Date
    May 2010
    Posts
    1,826

    Default Re: Subtracting 2 entered times

    If I had to do it in JavaScript, I would end up taking the hours and add the minutes / 60 for both times (by parsing out the text). Then subtract them and divide by 4 to get the 15 minute increments.

    That wouldn't be a lot of code and it should do the trick.

  5. #5
    "Certified" Alphaholic
    Real Name
    Gregg Schmidt
    Join Date
    Mar 2001
    Location
    Milwaukee
    Posts
    1,393

    Default Re: Subtracting 2 entered times

    As a rule I hate doing date/time math in javascript because of the extra work to get something that is so simple in xbasic or sql (especially MySQL), but here is a simple function I have that I think does the basics of what you want.
    Code:
    function dwait(a,l) {
    var t1 = new Date(a);
    var t2 = new Date(l);
    var results = 0;
    results = (t2 - t1)/1000;
    return results;
    }

Similar Threads

  1. Subtracting time with timeDiff
    By xido in forum Application Server Version 11 - Web/Browser Applications
    Replies: 10
    Last Post: 12-14-2015, 01:39 AM
  2. Subtracting records from a table
    By katesmith1985 in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 07-02-2014, 06:40 PM
  3. Subtracting records from a table
    By katesmith1985 in forum Alpha Five Version 11 - Desktop Applications
    Replies: 5
    Last Post: 07-02-2014, 12:32 PM
  4. subtracting NOW() fields
    By Walter in forum Alpha Five Version 6
    Replies: 10
    Last Post: 04-25-2005, 06:40 AM
  5. Subtracting Dates to get # of days?
    By Nathan White in forum Alpha Five Version 4
    Replies: 3
    Last Post: 07-17-2001, 06:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •