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

Calculate age

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

    Calculate age

    Could someone tell me how to caluculate someones age. I can get to how old someone will be by time the year is out with "(date()-DOB)/365" : where DOB is a birthdate, but if they haven't reached there birthday yet it is inaccurate.

    Thanks
    Joe

    #2
    RE: Calculate age

    It's been done (more than once). Search this board on "age".

    Bill
    Bill Hanigsberg

    Comment


      #3
      RE: Calculate age

      Joseph:
      Downloda this sample app.
      Save to a new directory and then unip the file to that directory.
      It will give you some date examples
      Charlie Crimmel

      Comment


        #4
        RE: Calculate age

        Change the 365 to 365.25. I would also make your answer an INT, which would make it a whole number, not a fraction.

        Comment


          #5
          RE: Calculate age

          Joseph,

          In Dr. Wayne's books he has a Global Function for calculating age that is accurate even for complicated situations such as leap years, etc.

          Dividing by 365 or even 365.25 can have errors at times.

          His example uses Alpha Five syntax, etc. and as a potential future user, I have not done this with Alpha 5, but have used the same technique with other languages/database products.

          If you have the books, just make a global function as he described.

          The basic idea is:

          1. Subtract the YEAR of DOB from the YEAR of current date or any date at which you need the age (such as admission date for medical records). We'll call that the "target date".

          2. If the MONTH of DOB is less than the MONTH of target date, then the age from step 1 is correct.

          3. If the MONTH of DOB is greater than the MONTH of target date, then subtract 1 from the result of step 1.

          4. If the MONTH of DOB is equal to the MONTH of target date,then if the DAY of DOB is less than or equal to the DAY of target date, the result is that from step 1, else subtract 1 from the step one result.

          Hope this helps.

          Brent

          Comment


            #6
            RE: Calculate age

            This one is from Ira... how does this NOT work?

            function Age as N(Birthday as D)
            years = val(left(cdate(date()),4))-val(left(cdate(birthday),4))
            if val(right(cdate(date()),4))>=val(right(cdate(birthday),4))
            age = years
            else
            age = years - 1
            end if
            end function

            Comment


              #7
              RE: Calculate age

              Funny, I posted that exact function code originally a long while ago. I am glad it is getting around. I hoped others would get some use out of it. Every test I have thrown at it works, including leap years etc.

              One of the great things about this forum is how code snippets and functions get passed around until no one is sure where the source was. Kinda like an open code system where many people end up using the best of everyone elses ideas.

              Jerry

              Comment


                #8
                RE: Calculate age

                Stephen,

                I don't think I wrote that code. For one thing, if I wrote it (as opposed to suggesting some modifications to someone else's), it would look more like this;


                function Age as N(Birthday as D)

                Age = year(date())-year(birthday)
                if val(right(cdate(birthday),4)) > val(right(cdate(date()),4))
                age = age - 1
                end if

                end function



                Try this function, which I did write.
                Note that Age= is one long expression line. Make sure it is all together or you should use a line continuation.



                function Age as N(Birthdate as D,CompareDate as D)

                ' Computes difference in years of CompareDate-Birthdate and
                ' returns fractional years.
                ' Fractional value is 0 on anniversary of date
                ' If Birthdate is blank, it uses current date
                ' If CompareDate is blank, it uses current date
                ' Value can return negative ages (which is to the future)

                ' Age({01/01/1999},{})

                IF trim(cdate(CompareDate))==""
                date2=DATE()
                ELSE
                date2=CompareDate
                END IF

                IF trim(cdate(BirthDate))==""
                date1=DATE()
                ELSE
                date1=Birthdate
                END IF

                yeardiff=YEAR(date2)-YEAR(date1)

                Age=yeardiff+IF(RIGHT(CDATE(date1),4)>RIGHT(CDATE(date2),4),(date2-ADDYEARS(date1,yeardiff-1))/365-1,(date2-ADDYEARS(date1,yeardiff))/365)

                end function


                Regards,

                Ira J. Perlow
                Computer Systems Design & Associates
                [email protected]
                Regards,

                Ira J. Perlow
                Computer Systems Design


                CSDA A5 Products
                New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                CSDA Barcode Functions

                CSDA Code Utility
                CSDA Screen Capture


                Comment


                  #9
                  RE: Calculate age

                  As usual, your methods are cleaner than mine and more inclusive. Your initial line to get the uncorrected age using year() is much better than what I posted. Don't even know why I took the direction I did, that was some time ago.

                  I do like your expanded function which has more possibilities to compare dates, not just use the current date. Much more useful. Looks like I will have to go back and take another look at my function. One thing I do like to do is break down long expressions into individual calculations. Makes it easier for my meager brain to follow what I was thinking when I created it.

                  Jerry

                  Comment


                    #10
                    RE: Calculate age

                    Ira,

                    I'm still a little confused (nothing new for me)... Don't you still need to divide by 365.25 to get an accurate difference in days?

                    Nice function; very clean.

                    Best regards,

                    Geoff Hollander

                    Comment


                      #11
                      RE: Calculate age

                      Geoffrey,

                      Dividing by 365.25 days is actually wrong in this case. The function determines the number of full years and then calculates the left-over days. With the left-over days, it would either be x or x+1 days left over for the partial year. Depending upon the day and month and whether it is a leap year, you may cross an extra day, but the fractional part of the year is still correct to be 365 for the divisor. 366 would be wrong most of the time and 365.25 would actually result in values less than correct most of the time. One could potentially determine if Feb 29th is in fact crossed and divide it by 366 in that case, but I believe that would not yield results that most would expect (in terms of a fractional value).

                      As far as I know, when the leap year case does happen, it seems like the last extra day 365/365 would yield a 1 extra year meaning that a person would be the same Integer age both on and the day before his birthday for that case.

                      Regards,

                      Ira J. Perlow
                      Computer Systems Design & Associates
                      [email protected]
                      Regards,

                      Ira J. Perlow
                      Computer Systems Design


                      CSDA A5 Products
                      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                      CSDA Barcode Functions

                      CSDA Code Utility
                      CSDA Screen Capture


                      Comment


                        #12
                        RE: Calculate age

                        The following works for me...(Today's date - DOB)/365.25
                        The divisor 365.25 takes care of leap years.

                        Comment


                          #13
                          RE: Calculate age

                          Ed,

                          That's what I'm talkin' 'bout. Ira?

                          Geoff Hollander

                          Comment


                            #14
                            RE: Calculate age

                            Geoffrey,

                            As a quick approximation, (date()-birthdate)/365.25 works OK. The problem shows itself most prominantly on the anniversary of the birthdate, where 3 out of 4 years have a non-zero fractional. So for today's date (3/12/2001) let's do an example;

                            age=(date()-{03/12/1951})/365.25
                            age=({03/12/2001}-{03/12/1951})/365.25
                            age=18263/365.25
                            age=50.001369

                            Almost any other day of a year the fractional is OK, but most people don't like to see a fractional day on an anniversary like 50.001369 years. Of course, you can always round it, and that might fill the needs of most, by for fractional years (used in, say interest calculations for motgages), it doesn't cut it.

                            There is another problem to deal with if the years happens to cross a century not divisible by 400 (e.g. 1900 and 2100). These years happen to not be a leap year that throws the fractional off even more. While this doesn't happen so much in the current century, historical dates, family trees etc won't work very good.

                            Regards,

                            Ira J. Perlow
                            Computer Systems Design& Associates
                            [email protected]
                            Regards,

                            Ira J. Perlow
                            Computer Systems Design


                            CSDA A5 Products
                            New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                            CSDA Barcode Functions

                            CSDA Code Utility
                            CSDA Screen Capture


                            Comment


                              #15
                              RE: Calculate age

                              Ira,

                              Thanks.

                              Geoff

                              Comment

                              Working...
                              X