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



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

Age in yrs and months

  • Filter
  • Time
  • Show
Clear All
new posts

  • Age in yrs and months

    Many age functions have been posted here that calculate an age as of the system date for a given birth date. The following is a good one, probably based on something someone else posted here in the past:

    function Age as N(DOB as D)
    '**Note: blank b-days will =this yr, i.e., 2000 in 2000
    '**Future b-days will have negative ages
    '**Ages 1 month to 11 months will be 0 cuz only doing years here
    case month(date())>month(dob)
    case month(date())=month(dob)>=day(dob)
    case else
    end select
    end function

    However, I recently had need to determine a person's age in years and months, including for babies who are less than a year old. I also needed to allow the user to substitute a future date for the usual system date so that they could easily determine how old someone would be at some date in the future.

    I present the following function here. I hope those more clever than I am can, in replies, improve upon it in terms of efficiency of elegance (maybe there is a wholly different and better way to do it). When the best shows up here I will post it in the code archive section.

    Please improve upon it or find errors.

    Raymond Lyons

    function AgeSTR as C(DOB as D,Date_Now as D)

    '**Note that if one wants just yrs as a numerical value
    '** val(calc->result string from AgeSTR) gives the age in yrs with blanks being 0

    dim ageSTR0 as c
    dim Cur_Month as n
    dim DOB_Month as n
    dim Months_to_add_sub as n

    If Cur_month>=DOB_Month
    End If

    case DOB = {}
    ageSTR0="Blank DOB"
    case Date_Now = {}
    ageSTR0= "Current Date is blank"
    case DOB > Date_Now
    ageSTR0="Invalid DOB"

    '**(1A) below is for cur mon is greater than mon of DB
    '**and cur day is greater than or = day of BD
    case month(date_Now)>month(dob)>=day(dob)
    ageSTR0=Ltrim(STR(year(Date_Now)-year(dob)))+" yrs "+Ltrim(STR(Months_to_add_sub))+" months"

    '**(1B) below is for cur mon is greater than mon of DB
    '**and cur day is less than day of BD
    case month(Date_Now)>month(dob) day of BD
    case month(Date_Now)=month(dob)>=day(dob)
    ageSTR0=Ltrim(STR(year(Date_Now)-year(dob)))+" yrs "+Ltrim(STR(Months_to_add_sub))+" months"

    '**(2B)below is where both dates are in the same month & cur day =day(dob)
    ageSTR0=Ltrim(STR(year(Date_Now)-year(dob)-1))+" yrs "+Ltrim(STR(Months_to_add_sub))+" months"

    '**(3B) below is for cur mon is less than mon of DB
    '**and cur day is less than day of BD (subtract 1 yr & subtract 1 month)
    case month(Date_Now)

  • #2
    RE: Age in yrs and months


    Try this function; 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
    ' If CompareDate is blank, it uses current date
    ' Value can return negative ages (which is to the future)

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

    IF CompareDate={}
    END IF


    end function


    Ira J. Perlow
    Computer Systems Design & Associates

    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


    • #3
      RE: Age in yrs and months

      Thanks Ira,

      I can see that your function results in a decimal. I thought about going that route and then turning the decimal into months. But I really wanted a function that would return years and months without any further converting through calculated fields. But of course there are lots of ways to skin this cat.



      • #4
        RE: Age in yrs and months

        Raymond, how do you mean to define the age in 'months'?

        If the current system date is June 1.
        And birthdate is May 31 of the current year.

        Is the child one month old? Or do you want the age to be zero months until 30 days have passed (except for February)?

        -- tom


        • #5
          RE: Age in yrs and months

          >>Or do you want the age to be zero months until 30 days have passed
          (except for February)?


          • #6
            RE: Age in yrs and months

            this function, elapsed_time(), gives the difference between 2 dates in years, months and days:

            function elapsed_time as C(date1 as D,date2 as D)
            dim y1 as n
            dim y2 as n
            dim m1 as n
            dim days as n
            dim d1 as d

            if date1>date2 then
            ' swap the dates
            dim tempd as d
            end if
            ' first approximation to year difference

            if makedate(month(date1),day(date1),year(date2))>date2 then
            end if

            if m1+month(date1)>12 then
            end if
            if makedate(mod(month(date1)+m1,12),day(date1),year(date1)+y2)>date2 then
            ' day is too far
            end if


            elapsed_time=alltrim(str(y1))+" years and "+
            alltrim(str(m1))+" months and "+alltrim(str(days))+" days"

            end function


            • #7
              RE: Age in yrs and months


              I think you need to include the makedate function, unless it is something new a beta you are using. In any case it won't work as is in build 230.



              • #8
                RE: Age in yrs and months

                Peter e-mailed the makedate function to me. Here it is, in case anyone is interested. I'm not sure what, if anything I'll put in the code archive on all this.


                function makedate as D(m as N,d as N,y as N)
                ' when give month, day and year parameters, returns the date or the first
                ' preceding date that is a valid date
                ' e.g., makedate(2,29,97) returns {2/28/97}

                if m>12 .or. m


                • #9
                  RE: Age in yrs and months


                  Here is a much easier function to return the results you want;

                  function AgeMonths as N(Date1 as D,CompareDate as D)

                  ' Computes difference in months of CompareDate-Date1
                  ' If CompareDate is blank, it uses current date
                  ' Value can return negative ages (which is to the future)

                  ' Examples of usage
                  ' AgeMonths({01/01/1999},{})
                  ' AgeMonths({01/01/1999},{06/10/1999})

                  ' To compute Age in Years, just divide the result by 12, as in
                  ' AgeMonths({01/01/1999},{})/12


                  IF CompareDate={}
                  END IF

                  IF Day(Date2)>=Day(Date1)
                  AgeMonths=(YEAR(Date2)*12)+MONTH(Date2)-(YEAR(date1)*12)-Month(date1)+ ((Day(Date2)-Day(Date1))/31)
                  ' Last month from Date2

                  ' First day of last Month

                  ' Last day of previous month from date2

                  AgeMonths=(YEAR(Date2)*12)+MONTH(Date2)-(YEAR(date1)*12)-Month(date1)-1+ (Date2-(LstMo1st-1+Min(DAY(LstMoLst),DAY(Date1))))/31
                  END IF

                  end function


                  Ira J. Perlow
                  Computer Systems Design & Associates

                  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