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

Compare 2 dates using javascript

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

    Compare 2 dates using javascript

    OK, I have a feeling this has been asked before but I've searched and can't find exactly what I need.

    On my UX, I have a date field named GL_DATE and its display format is: time("MM/dd/yy",<value>)

    I want to check the date entered by the user to see if it is:
    1 - After today (in the future)?
    2 - Over a year old (from today)
    3 - Prior to another date field (CURR_PERIOD_BEGIN) in the ux
    4 - After another date field (CURR_PERIOD_END) in the ux

    I know how to do this with a callback to Xbasic, but I would like to know if it's possible in javascript.

    I wrote this much and then became stumped about how to get javascript to see the gldate as a date because I know it will be a string:

    var currRowNum = {dialog.Object}.getRepeatingSectionActiveRow('CONTAINER_1');
    var glDate = {dialog.object}.getValue('GL_DATE:currRowNum');
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

    #2
    Re: Compare 2 dates using javascript

    you should be able to do all these calculations with javascript gettime method of the date object
    for example
    var today = new Date()
    today.getTime() will give you milliseconds from jan 1st 1970 for today
    similarly you can get all these other numbers and compare whether they meet your criteria.
    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: Compare 2 dates using javascript

      Carol,

      This will convert your date string to a Javascript Date object:

      Code:
      var glDate = new Date(Date.parse({dialog.object}.getValue('GL_DATE:currRowNum'));
      Some other things you can do:

      Code:
      var today = new Date();
      var tomorrow = new Date(today.getTime() + 24*60*60*1000); // 24 hrs * 60 mins * 60 secs * 1000 milliseconds
      var yesterday = new Date(today.getTime() - 24*60*60*1000);
      var nextYear = new Date(today.getTime() + 365*24*60*60*1000);

      Comment


        #4
        Re: Compare 2 dates using javascript

        Thanks for the replies but I am just too ignorant about javascript and dates, even though I keep trying to go and read things about them. Don't laugh, but here is my latest failed attempt to get an alert from the onChange event of the GL_DATE.. You can see my other failed attempts by looking at the stuff that is commented out. (GL_DATE is a field on a repeating section row and BALANCE_FWD_DATE is not in the repeating section.)

        Code:
        var currRowNum = {dialog.Object}.getRepeatingSectionActiveRow('CONTAINER_1');
        var glDate = new Date({dialog.object}.getValue('GL_DATE:currRowNum'));
        //var glDate = {dialog.object}.getValue('GL_DATE:currRowNum');
        //var glDate = new Date(Date.parse({dialog.object}.getValue('GL_DATE:currRowNum'));
        var cnvrtGLDate = glDate.getTime()
        var BalFwdDate = new Date({dialog.object}.getValue('BALANCE_FWD_DATE'));
        //var BalFwdDate = {dialog.object}.getValue('BALANCE_FWD_DATE');
        //var balFwdDate = new Date(Date.parse({dialog.object}.getValue('BALANCE_FWD_DATE'));
        var cnvrtBalFwd = balFwdDate.getTime()
        
        //if(glDate < BalFwdDate){
        if(cnvrtGLDate < cnvrtBalFwd){
        	alert('The date entered is prior to the Balance Forward date for your accounting books and will not be allowed when Submitting this record.');
        }
        Last edited by kingcarol; 06-03-2014, 07:09 PM.
        Carol King
        Developer of Custom Homebuilders' Solutions (CHS)
        http://www.CHSBuilderSoftware.com

        Comment


          #5
          Re: Compare 2 dates using javascript

          http://screencast.com/t/DyNNKnVZmdJl

          take a look at this.
          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: Compare 2 dates using javascript

            Thank you, Ghandi. That looks promising. I will try it later tonight or in the morning and let you know.
            Carol King
            Developer of Custom Homebuilders' Solutions (CHS)
            http://www.CHSBuilderSoftware.com

            Comment


              #7
              Re: Compare 2 dates using javascript

              I have followed your steps, Ghandi, with no luck. I am wondering if I need to update my version. I have been having no problems with version 1970-4257 so have stuck with it. Is it possible that the new Date() OR the getTime() stuff only works in a later release?
              Carol King
              Developer of Custom Homebuilders' Solutions (CHS)
              http://www.CHSBuilderSoftware.com

              Comment


                #8
                Re: Compare 2 dates using javascript

                Carol,

                I really don't like dates... they're nasty things... in any language. They never match... there's always a format issue... you always have to remember, or find, the calc to figure out days, years, etc.

                So... I use moment.js. It's a tiny javascript library... clearly written by someone who both loves and hates dates.

                It does take a little bit of getting used to... but it's well worth it.

                Attached is the moment.js file in a zip file, along with a UX that demonstrates what you're looking for.

                And here is what it looks like...

                http://www.youtube.com/watch?v=FXGn_fE_nuY
                Attached Files

                Comment


                  #9
                  Re: Compare 2 dates using javascript

                  David, that looks promising! I watched as I'm heading to sleep and will definitely try it in the morning. How kind of you to take the time to do that.
                  Carol King
                  Developer of Custom Homebuilders' Solutions (CHS)
                  http://www.CHSBuilderSoftware.com

                  Comment


                    #10
                    Re: Compare 2 dates using javascript

                    I have followed your steps, Ghandi, with no luck. I am wondering if I need to update my version. I have been having no problems with version 1970-4257 so have stuck with it. Is it possible that the new Date() OR the getTime() stuff only works in a later release?
                    they are javascript, not alpha stuff. incidentally I am on version 11, remember the abandoned one, that one. you are with the prized child.
                    if after reviewing david's and still need some explanation post back exactly what you want to be done one of us will help.

                    edit: I just looked at david's video..
                    it is a good video, but a little thing like this you can write your own calculation without moment.js library.
                    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


                      #11
                      Re: Compare 2 dates using javascript

                      Hi Ghandi, Before I try David's suggestion, I thought I'd post what I've tried based on your suggestion. I've now made a simple ux to do the testing and it is attached. Below is the code I've been trying in the onChange event of the GL_DATE. It produces no alert when I enter a date prior to the BALANCE_FWD_DATE.

                      Code:
                      var currRowNum = {dialog.Object}.getRepeatingSectionActiveRow('CONTAINER_1');
                      var gld = {dialog.object}.getValue('GL_DATE:currRowNum');
                      var glDate = new Date(gld)
                      var bfd = {dialog.object}.getValue('BALANCE_FWD_DATE');
                      var balFwdDate = new Date(bfd)
                      if(glDate.getTime() < balFwdDate.getTime()){
                      	alert('The date entered is before the balance forward date.');
                      }

                      ZZZDatesTest.a5wcmp
                      Carol King
                      Developer of Custom Homebuilders' Solutions (CHS)
                      http://www.CHSBuilderSoftware.com

                      Comment


                        #12
                        Re: Compare 2 dates using javascript

                        I will post a video in aminute,
                        but when you are in an active row you do not need to indicate the row number as 'GL_DATE:currRowNum'
                        just simple gl_date should be fine.
                        I will work out a sample on repeating section post it soon for you
                        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: Compare 2 dates using javascript

                          OK, now I've tested using David's suggestion and I'm still not having any luck. My component using that one is attached.

                          ZZZDatesTestMoment.a5wcmp
                          Carol King
                          Developer of Custom Homebuilders' Solutions (CHS)
                          http://www.CHSBuilderSoftware.com

                          Comment


                            #14
                            Re: Compare 2 dates using javascript

                            Now I think I know the problem. I am putting the javascript into the onChange event of the GL_DATE. I just put a button on BOTH Gandhi's and David's suggestions and am getting the desired alert from both of them when I click a button. I guess I'm going to have to call the on click event of buttons that are hidden using show hide expression. Apparently the onChange event does not get the value of the date object.
                            Carol King
                            Developer of Custom Homebuilders' Solutions (CHS)
                            http://www.CHSBuilderSoftware.com

                            Comment


                              #15
                              Re: Compare 2 dates using javascript

                              http://screencast.com/t/Sv0QGMMUHr7

                              take a look at this screencast.
                              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