Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Time from Seconds

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Time from Seconds

    I am building a UX in V12 with 4 textbox controls
    Timein|TIME
    Timeout|TIME
    Time_total|TIME
    Secs |TIME

    I have a button that runs some javascript as follows:
    Code:
    d1 = new Date();
    d1 = d1.toFormat('MM/dd/yyyy 0h:0m:0s am');
    {dialog.Object}.setValue('time_out',d1);
    stim = {dialog.Object}.getValue('time_in');
    etim = {dialog.Object}.getValue('time_out');
    nt1 = new Date(stim);
    nt2 = new Date(etim);
    timdif = nt2.getTime() - nt1.getTime();
    secs = timdif/1000;
    
    elapsedtime = //This is where I need help!
    
    {dialog.Object}.setValue('seconds',secs);
    {dialog.Object}.setValue('time_total',elaspedtime);
    I want the elasped time to be X hrs X mins and X seconds
    EG 1:25:03

    Secs gives me the the exact number of expired seconds between nt1 and nt2

    Time in is default Now()
    and Time Out is d1 formatted the same as Now()

    SO currently values might be
    Time In: 01/24/2016 03:45:35 pm
    Time Out: 01/24/2016 03:45:37 pm
    Secs results in 2
    meaning 2 seconds have passed.
    so I would like to see
    00:00:02

    I don't want it to read 3663 seconds have passed I would want it to say
    1:01:03
    I cannot seem to get anywhere with this...all of the date and time functions seem useless for this.
    NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

    #2
    Re: Time from Seconds

    Code:
    var secs = 3663;
    var h = Math.floor(secs/3600);
    if (h < 10) {
    h = "0"+h;
    }
    var m = Math.floor((secs%3600)/60);
    if (m < 10 ) {
    m = "0"+m;
    }
    var s = secs%60;
    if (s < 10 ) {
    s = "0" + s;
    }
    alert(h + ":" + m + ":" + s);
    elapsed_time = h + ":" + m + ":" + s;
    this is tested with the number you posted, substitute with the real values by getting the control values.
    edit:
    time_total should a character field. you have it as TIME, not good.
    secs should be number not TIME, not good.
    Last edited by GGandhi; 01-24-2016, 09:16 PM.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    [email protected]
    Skype:[email protected]
    1 914 924 5171

    Comment


      #3
      Re: Time from Seconds

      GGandhi
      is that vbasic or JavaScript? For some reason I am lost on the execution.
      NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

      Comment


        #4
        Re: Time from Seconds

        you are working with javascript, right. this is the extension of your function.
        thanks for reading

        gandhi

        version 11 3381 - 4096
        mysql backend
        http://www.alphawebprogramming.blogspot.com
        [email protected]
        Skype:[email protected]
        1 914 924 5171

        Comment


          #5
          Re: Time from Seconds

          d1 = new Date();
          d1 = d1.toFormat('MM/dd/yyyy 0h:0m:0s am');
          {dialog.Object}.setValue('time_out',d1);
          stim = {dialog.Object}.getValue('time_in');
          etim = {dialog.Object}.getValue('time_out');
          nt1 = new Date(stim);
          nt2 = new Date(etim);
          timdif = nt2.getTime() - nt1.getTime();
          secs = timdif/1000;

          //gandhi addition to your code
          var h = Math.floor(secs/3600);
          if (h < 10) {
          h = "0"+h;
          }
          var m = Math.floor((secs%3600)/60);
          if (m < 10 ) {
          m = "0"+m;
          }
          var s = secs%60;
          if (s < 10 ) {
          s = "0" + s;
          }
          alert(h + ":" + m + ":" + s);
          {dialog.Object}.setValue('seconds',secs);
          {dialog.Object}.setValue('time_total',elaspedtime);

          make sure secs in the dialog is a numerical field and total_time is character field.
          thanks for reading

          gandhi

          version 11 3381 - 4096
          mysql backend
          http://www.alphawebprogramming.blogspot.com
          [email protected]
          Skype:[email protected]
          1 914 924 5171

          Comment


            #6
            Re: Time from Seconds

            d1 = new Date();
            d1 = d1.toFormat('MM/dd/yyyy 0h:0m:0s am');
            {dialog.Object}.setValue('time_out',d1);
            stim = {dialog.Object}.getValue('time_in');
            etim = {dialog.Object}.getValue('time_out');
            nt1 = new Date(stim);
            nt2 = new Date(etim);
            timdif = nt2.getTime() - nt1.getTime();
            secs = timdif/1000;
            while you can certainly do this, but

            var d1 = new Date();
            d1 = d1.toFormat('MM/dd/yyyy 0h:0m:0s am');
            {dialog.Object}.setValue('time_out',d1);
            var stim = {dialog.Object}.getValue('time_in');
            var etim = {dialog.Object}.getValue('time_out');
            var nt1 = new Date(stim);
            var nt2 = new Date(etim);
            var timdif = nt2.getTime() - nt1.getTime();
            var secs = timdif/1000;

            is better.
            thanks for reading

            gandhi

            version 11 3381 - 4096
            mysql backend
            http://www.alphawebprogramming.blogspot.com
            [email protected]
            Skype:[email protected]
            1 914 924 5171

            Comment


              #7
              Re: Time from Seconds

              Thanks GGandhi,
              I just realized my problem was the word "elapsedtime"
              No telling how many variations of what you gave me I had already tried without success! I spelled it one way naming the var and another way in the setvalue statement!
              I just realized it when I looked at your spelling of it! lol.

              I knew it all seemed like it SHOULD work!

              Thanks again!
              NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

              Comment


                #8
                Re: Time from Seconds

                I do have a logic question though. You suggest that the total_time be a C field. I have it as a TIME field in Mysql and as a Time field type in the UX.
                All seems to work as expected. I eliminated the seconds field and strictly use the secs variable for the math in the javascript.
                My question is why are you saying the field SHOULD be a C field?
                I do plan on creating a report later on (maybe a list, maybe a grid), and adding these "elapsed_time" values to get a total of the time spent - would I be better off setting them all up as C or T fields?
                thoughts?
                NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                Comment


                  #9
                  Re: Time from Seconds

                  If it works, then don't fix it. I did not update a MySQL table to see, just worked on the calculation.
                  Good luck as always.
                  thanks for reading

                  gandhi

                  version 11 3381 - 4096
                  mysql backend
                  http://www.alphawebprogramming.blogspot.com
                  [email protected]
                  Skype:[email protected]
                  1 914 924 5171

                  Comment


                    #10
                    Re: Time from Seconds

                    OK, still working on this going forward. It works. I do need guidance on rounding down a value. Everything I try either gives me a whole number or it kills the code.
                    Secondly, if I open an existing record, I get NaN if I run the code again. This seems to be based on what is submitted. My database field for the start time and the end time is DateTime so I thought it was a number...??? any thoughts on that?
                    Heres what I got: 2 buttons the first one does this:

                    Code:
                    stime = new Date();
                    stime = stime.toFormat('MM/dd/yyyy 0h:0m:0s am');
                    {grid.Object}.setValue('D','HOURS_START',stime);
                    Button 2 does this:

                    Code:
                    d1 = new Date();
                    d1 = d1.toFormat('MM/dd/yyyy 0h:0m:0s am');
                    {grid.Object}.setValue('D','HOURS_STOP',d1);
                    stim = {grid.Object}.getValue('D','HOURS_START');
                    etim = {grid.Object}.getValue('D','HOURS_STOP');
                    payr = {grid.Object}.getValue('D','PAYRATE');
                    nt1 = new Date(stim);
                    nt2 = new Date(etim);
                    timdif = nt2.getTime() - nt1.getTime();
                    secs = timdif/1000;
                    mins = secs/60;
                    
                    //gandhi addition to your code
                    var h = Math.floor(secs/3600);
                    if (h < 10) {
                    h = "0"+h;
                    }
                    var m = Math.floor((secs%3600)/60);
                    if (m < 10 ) {
                    m = "0"+m;
                    }
                    var s = secs%60;
                    if (s < 10 ) {
                    s = "0" + s;
                    }
                    var cpm = payr/60;
                    var totalc = cpm*mins;
                    var rounded = "$"+totalc;
                    
                    
                    elapsedtime = h + ":" + m + ":" + s;
                    {grid.Object}.setValue('D','minutes',m);
                    {grid.Object}.setValue('D','seconds',secs);
                    {grid.Object}.setValue('D','HOURS_TOTAL',elapsedtime);
                    {grid.Object}.setValue('D','GROSSPAY',rounded);
                    Now, goal one is to make Grosspay look like a number and act like a number...rounded down to currency. This seems impossible!
                    Goal two, is to be able to save a record - reopen it and click button two again without NaN showing up for the calculations...

                    Any ideas?

                    All fields are either DateTime
                    or INT in the database.

                    What can I do?
                    NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                    Comment


                      #11
                      Re: Time from Seconds

                      var rounded = "$"+totalc;
                      var rounded = "$"+totalc.toFixed(2);
                      should give you currency looking value.
                      All fields are either DateTime
                      or INT in the database.
                      the value rounded is not an INT value.

                      edit:
                      Goal two, is to be able to save a record - reopen it and click button two again without NaN showing up for the calculations...
                      if you save the totalc to the database that should be an integer value as opposed to rounded which is a string.
                      but you know your database, the data needed to go in and taken out.

                      edit2:
                      My database field for the start time and the end time is DateTime so I thought it was a number...???
                      as far as i know Datetime fields are not integers, they are strings.
                      Last edited by GGandhi; 02-11-2016, 08:26 AM.
                      thanks for reading

                      gandhi

                      version 11 3381 - 4096
                      mysql backend
                      http://www.alphawebprogramming.blogspot.com
                      [email protected]
                      Skype:[email protected]
                      1 914 924 5171

                      Comment


                        #12
                        Re: Time from Seconds

                        Ok, so the datetime fields that my buttons accurately work - work fine until I re-open the record and it pulls the start datetime from the database as a string.
                        What do I need to do to transform/convert the value BACK to a similar format that the original code inserted with date()
                        that must've been a number since the code works on create (button one code)
                        So it gets saved as a string and then re-opening it as a string makes it fail - how do I get it back into a workable number when the record loads?

                        any ideas?
                        NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                        Comment


                          #13
                          Re: Time from Seconds

                          You create a date object with that string and convert to whatever number you want
                          thanks for reading

                          gandhi

                          version 11 3381 - 4096
                          mysql backend
                          http://www.alphawebprogramming.blogspot.com
                          [email protected]
                          Skype:[email protected]
                          1 914 924 5171

                          Comment


                            #14
                            Re: Time from Seconds

                            my friend, that much I know i am however lost in the execution!
                            So my grid opens, and I select the record-----> it opens the detail view and the startdatetime loads in its place, but now it is a string.
                            I want it to ALWAYS be a number to perform the code that runs in button two - the same code that worked prior to saving the record.
                            The startdatetime was originally created with button one (date())
                            obviously I want it to be a number as per your suggestion, I don't know how to load an existing record and run button2 code!

                            Secondly, gghandi you have been so very helpful to me I just wanted to say thanks again! The rounded final result worked as expected and was so simple.
                            my attempt of round(totalc,2) didn't work and now from what you suggested I can see how far off my syntax was...now perhaps I can learn to use other functions in future code as well - so again thanks!
                            NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                            Comment


                              #15
                              Re: Time from Seconds

                              I want it to ALWAYS be a number to perform the code that runs in button two
                              on that button onClick event
                              var t1 = {grid.object}.getValue('D'......);
                              then
                              t1 = new Date(t1);
                              then
                              secs = t1.getTime()/1000;
                              like that build your numbers.
                              thanks for reading

                              gandhi

                              version 11 3381 - 4096
                              mysql backend
                              http://www.alphawebprogramming.blogspot.com
                              [email protected]
                              Skype:[email protected]
                              1 914 924 5171

                              Comment

                              Working...
                              X