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

add time in a grid - calculated field expression

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

    add time in a grid - calculated field expression

    As the title suggests - this is in a grid and I hope a fairly simple question
    I have one field called "starttime" with a default value of
    =time("0h:0m am",now())
    I just want the time and for the end time I want to add 90 minutes in a hidden field called "endtime"



    I thought it would be real nifty if I could simply put =time("0h:0m am",now()+ "0h:90m")
    or something (that actually works) as the calculated field expression.

    Obviously, that doesn't work - can someone recommend a way to add_minutes - 90 minutes that is to what ever the value is in my "starttime" field.


    I guess, I could resort to some javascript event to bust it down into minutes, add 90 and then return the value in a setvalue call but I was hoping there was something like add_minutes(starttime,90) that would work that I could just put into the calculated field expression setting.

    Anyone have 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?"

    #2
    Re: add time in a grid - calculated field expression

    The grid and ux components have a client-side method named ".addTime()". This is the example from the Insert Method dialog.

    Code:
    var d1 = new Date();
    //add 1 year
    d2 = d1.addTime('year',1);
    //add 1 year, 3 months, 10 days to a date value
    var d1 = new Date();
    d2 = d1.addTime('year',1).addTime('month',3).addTime('day',10);
    So... having .addTime... you could do something like this...

    Code:
    var startTime = {grid.Object}.getValue('G','STARTTIME',{Grid.RowNumber});
    var d1 = new Date(startTime);
    var d2 = d1.addTime('minute',90);
    var d3 = d2.toFormat("0h:0m am");
    console.log(d1 + " " + d2 + " " + d3);
    Last edited by Davidk; 10-08-2017, 02:07 PM.

    Comment


      #3
      Re: add time in a grid - calculated field expression

      I just looked a that - thanks for pointing that out. I should be able to sort it from there, it just seems like add_minutes(fieldname,90) would have been easier but alas it doesn't work like that and the documentation for that function doesn't have an example to show me that I might be trying to use something that wouldn't work there. Anyways, again thanks. I should've looked there.
      So now, I need to figure out how to best implement it. I should run this code everytime there is a change to the starttime as well as on initial load or at the very least during a button click prior to submit might be best, that way it only runs once when it's needed.
      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: add time in a grid - calculated field expression

        Since this is a detail view of a grid I wrote it to reflect that as follows:
        Code:
        var startTime = {grid.Object}.getValue('D','TASK_STARTTIME');
        var d1 = new Date(startTime);
        var d2 = d1.addTime('minute',90);
        var d3 = d2.toFormat("0h:0m am");
        {grid.Object}.setValue('D','TASK_ENDTIME',d3);
        I put this code in the on change event of start time but I am getting Na:Na am

        I thought toFormat would straighten that out.
        Last edited by CharlesParker; 10-08-2017, 03:20 PM.
        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


          #5
          Re: add time in a grid - calculated field expression

          Looking at the methods if you filter by Grid or Detail View, the add time method goes away - are you sure it can be used in a grid?
          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


            #6
            Re: add time in a grid - calculated field expression

            var startTime = {grid.Object}.getValue('D','TASK_STARTTIME');
            var d1 = new Date(startTime);
            i don't think you can create a date with just
            0h:0m AM of the now().
            that is why there is error.
            you might need to add date part too, i think.
            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: add time in a grid - calculated field expression

              Yes I was thinking that the date was getting put into the time part causing the Na as part of what probably is "NaN"
              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: add time in a grid - calculated field expression

                But if you only had add_minutes... then you'd need other methods... add_hours, add_days. Why not have one function that takes a parameter and will add anything you want?

                For your Na issue, there are so many variables that could apply... but nothing else specified in the post. Try this...

                Code:
                var startTime = {grid.Object}.getValue('D','REPORTTIME');
                var d1 = new Date();
                d1.fromFormat(startTime,"0h:0m am");
                var d2 = d1.addTime('minute',90);
                var d3 = d2.toFormat("0h:0m am");
                setTimeout(function(){
                	{grid.Object}.setValue('D','TASK_ENDTIME',d3);
                },200);
                You many not need the setTimeout. Try it with and without. Grids are funny sometimes.

                Comment


                  #9
                  Re: add time in a grid - calculated field expression

                  Yes I was thinking that the date was getting put into the time part causing the Na as part of what probably is "NaN"
                  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


                    #10
                    Re: add time in a grid - calculated field expression

                    OK, Davids suggestion in post #8 was the one that fixed the NaN issue - thanks for the support! I left in the timeout because I figured it can't hurt - how long is 200 REALLY anyways, lol. Dates and Times are such a PIA, this was the one thing holding me back on a sql insert statement I was really aiming at!
                    So my final working code was as follows:
                    Code:
                    var startTime = {grid.Object}.getValue('D','TASK_STARTTIME');
                    var d1 = new Date();
                    d1.fromFormat(startTime,"0h:0m am");
                    var d2 = d1.addTime('minute',90);
                    var d3 = d2.toFormat("0h:0m am");
                    setTimeout(function(){
                    	{grid.Object}.setValue('D','TASK_ENDTIME',d3);
                    },200);
                    No real change other than the field name, but I figured it would be helpful to a new guy regardless to post it. It seems it was really the "fromFormat" line that did it but it sure is wierd that we go FROM the same format TO the same format - regardless - thanks for the timely and much needed help guys!
                    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: add time in a grid - calculated field expression

                      Would it be correct to say that the FROM format brought it into a DATE object from a TIME object? And would it also be correct to say that the TO format changed it from a DATE object to the TIME object?
                      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


                        #12
                        Re: add time in a grid - calculated field expression

                        you might want to cheat a little here. i will test it little later.
                        Code:
                        var startTime = {grid.Object}.getValue('D','REPORTTIME');
                        var d1 = new Date("00/00/0000" + startime);
                        var d2 = d1.addTime('minute',90);
                        
                        {grid.Object}.setValue('D','TASK_ENDTIME',d2.toFormat("0h:0m 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


                          #13
                          Re: add time in a grid - calculated field expression

                          Originally posted by CharlesParker View Post
                          Would it be correct to say that the FROM format brought it into a DATE object from a TIME object? And would it also be correct to say that the TO format changed it from a DATE object to the TIME object?
                          You don't have a Time object. .getValue() returns a string in this case. This is why it's important to know how things are configured and used and not guess.

                          With the default time code you posted... and depending on a format you may have, you get back a string of "05:04:00 00 pm". This is fine for using with new Date(). However, if you use a Time Picker, then you get back a value of "5:04 AM" which is not ok for new Date()... and which is why you need also to .fromFormat() to turn it into a Date Object.

                          .toFormat takes a Date Object and changes it to a string.

                          Comment


                            #14
                            Re: add time in a grid - calculated field expression

                            the easiest will be to have date and time for that part, then it will easy to add minutes to that value by any method and added benefit is you can use the new calculated value in another calculation if you need one, but if you must have only time part then you can get hold of the parts of the value and calculate the new string and add it to the end time which will be a string but may not be used for any calculations.
                            to me this is hard way to do.
                            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


                              #15
                              Re: add time in a grid - calculated field expression

                              Thanks David! If nothing else I am smarter for asking.


                              Gandhi, there's a pretty good reason I am using only the time part. I am using Jims Coltz calendar for scheduling so I need the dates and times as single sepearte fields in the database for start and end according to how I have my calendar options setup - his calendar also has options for combined date/time fields but I find it much easier to make the modifications that I have in tweaking his calendar to my needs to use separate fields.

                              The big picture here is - I have a phone log entry table that once you input the information from the caller, name address, etc you can in a single click create a customer in the customers table, a job in the jobs table, an appointment in the calendar table and finally an invoice if you want to as well. At that point, using the mobile app for a technician he can log in and see his next appointment and email the customer their invoice from there - it's already created when the secretary entered it ONCE! This endtime is always set for 90 minutes after teh starttime because that is the average time it takes AND I do not want to write error code for dates and times that would throw off the calendar. Users only have to select the start date and the start time and that will create a 90 minute appointment for the technician they chose com,plete with map links and click to call buttons on their agenda.

                              Of course, all operations can be tweaked at the individual component levels - but man this gets it pretty much done in a click! I will probably add in the ability to SMS through twilio a text to the tech with a "You've got a job!" text.

                              It is amazing what AS can do in a single component - it's just that one little turd of a date/time issue floating in the punch bowl of my component that I needed to take care of, lol


                              thanks again (to both of you)
                              ~Cheers
                              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

                              Working...
                              X