Alpha Video Training
Results 1 to 13 of 13

Thread: convert age in months to years,months,days

  1. #1
    Member
    Real Name
    Jim Doyle
    Join Date
    Dec 2006
    Location
    Krum, Texas
    Posts
    213

    Default convert age in months to years,months,days

    Use calculation below to calculate age in months on input of birth date in "DOB" field -writes to a field for age in months.
    12*(YEAR(SHOW_DATE)-YEAR(DOB))+MONTH(SHOW_DATE)-MONTH(DOB)+IF(DAY(DOB)>=DAY(SHOW_DATE),1,0)

    Need the age in months converted to years,months,days to be written in another field called "aginyears"
    or
    With input of birth date in DOB field to calclulate age in years,months,days for field "aginyears"

    Any help would be appreciated
    Jim

  2. #2
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: convert age in months to years,months,days

    Jim,

    This to start you off.

    Age=date()-DOB
    months=age*12

    You will need to make some adjustment between the number of months in the DOB year and number of months to date in the current year.
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

  3. #3
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: convert age in months to years,months,days

    I have a post in the code archive forum

    http://msgboard.alphasoftware.com/al...onths-and-days

    see if that is useful.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  4. #4
    Member
    Real Name
    Jim Doyle
    Join Date
    Dec 2006
    Location
    Krum, Texas
    Posts
    213

    Default Re: convert age in months to years,months,days

    First off Thanks Mr.Hubert for your reply.

    Mr. Gandri,
    Your code was exactly what I was looking for. I knew that I had seen on the message board but was unable to find it. Thanks!

    However now upon executing "New Record" (a button on menu for adding a new animal) the dialog box for the year,month pops up.
    Can not get past it to enter information about the animal.
    Can you help?
    Jim

  5. #5
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: convert age in months to years,months,days

    take a look at this:
    I normally do not work on desktop, my comfort level is not that good with desktop. so please bear with me.
    http://screencast.com/t/G8fKAM1dUI
    Code:
    FUNCTION alpha_ageFull2 AS C (dateOfBirth AS D, showDate AS D )
    	
    		if dateOfBirth > showDate then
    		alpha_ageFull2 = "Date of birth is later than the end date!"
    		else
    dim y1 as n
    dim y2 as n
    dim m1 as n
    dim m2 as n
    dim d1 as n
    dim d2 as n
    dim dY as n
    dim dM as n
    dim dD as n
    dim leapYr as l
    
    
    y1 = year(dateOfBirth)
    y2 = year(showDate)
    m1 = month(dateOfBirth)
    m2 = month(showDate)
    d1 = day(dateOfBirth)
    d2 = day(showDate)
    
    select
    	case mod(y2,4)>0
    		leapYr = .f.
    	case mod(y2,400)=0
    		leapYr = .t.
    	case mod(y2,100)=0
    		leapYr = .f.
    	case else
    	 	leapYr = .t.
    end select
    
    
    if ( d2-d1 < 1)
    	select 
    		case m2 = 1
    			d2 = d2+31
    		case m2 = 2
    			if leapYr 
    				d2 = d2+29
    			else	
    			d2 = d2+28
    			end if
    		case m2 = 3
    			d2 = d2+31
    		case m2 = 4
    			d2 = d2+30
    		case m2 = 5
    			d2 = d2+31
    		case m2 = 6
    			d2 = d2+30
    		case m2 = 7
    			d2 = d2+31
    		case m2 = 8
    			d2 = d2+31
    		case m2 = 9
    			d2 = d2+30
    		case m2 = 10
    			d2 = d2+31
    		case m2 = 11
    			d2 = d2+30
    		case m1 = 12
    			d2 = d2+31
    		end select	
    	m2 = m2-1
    	end if
    	if (m2 < m1)
    		y2 = y2-1
    		m2 = m2+12
    		end if
    dY = y2-y1
    dM = m2-m1
    dD = d2-d1
    alpha_ageFull2 = "Age: "+dy+" years " +dM+" months "+dD+" days "
    end if
    
    	
    END FUNCTION
    http://screencast.com/t/e9ZRs2ee
    improved screencast
    corrected the code and the screencast
    Last edited by GGandhi; 02-16-2014 at 11:07 AM. Reason: improved screencast
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  6. #6
    Member
    Real Name
    Jim Doyle
    Join Date
    Dec 2006
    Location
    Krum, Texas
    Posts
    213

    Default Re: convert age in months to years,months,days

    Mr. Gandhi,
    Again thanks for your help. I have implemented the code into my application and it works.
    I am having a little difficulty with making the script run like I would like to have it run.
    Attached is my application.
    Open main menu-open Llamas.
    On input of llama birth date-would like for it to populate the code with startdate (which is "DOB" field) and enddate (which has obtained from "show_date" field ) and then display age in years, month,days.
    This would do the task in one operation as opposed to two as I now have.

    Please understand that I am a novice at this and sometimes may not use the correct terminology.
    Jim
    Attached Files Attached Files

  7. #7
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: convert age in months to years,months,days

    I will redo your database and send back.
    in the meantime
    take a look at the second video below the code and study the code. I revised earlier after rereading your post.
    you have copied the xdialog method, but I am using function and calling the function from on change event on your show_date field.
    also I will be changing your age_in_years from numeric to character to show the string.
    it will take about 20 minutes or so then I will upload the zipped file.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  8. #8
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: convert age in months to years,months,days

    okay
    I did some modifications to the table and the form.
    I changed the yearsold to character field, I changed the animal_age from calculated field to user entered, I removed the button to calculate the age, I removed the event firing the xdialog on canedit event of the show_date. I changed the tab order to suit me, that is not my advice for you to change.

    here are the two videos
    llama1
    http://screencast.com/t/ERbG5NdOdw

    llama2
    http://screencast.com/t/lirp5EeA

    Please understand that I am a novice at this and sometimes may not use the correct terminology.
    work looks very good to me.
    Attached Files Attached Files
    Last edited by GGandhi; 02-17-2014 at 07:22 AM.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  9. #9
    Member
    Real Name
    Jim Doyle
    Join Date
    Dec 2006
    Location
    Krum, Texas
    Posts
    213

    Default Re: convert age in months to years,months,days

    Again Mr. Gandhi thank you for your input.
    I have changed the tab order to suit a better flow of data input.
    Changed the show_date so that it defaults to the last entry. When using the application the show _date will stay the same until you start a new set of show data for a different show. By changing to default you are not having to input show_date for every new animal entered. The only thing I can not solve is upon changing the DOB (because of wrong input by user-typo) for an animal already in the data base the code will not recalculate the age. I have tried several different things-never recalculates age.
    Attached latest zip

    Jim
    Attached Files Attached Files

  10. #10
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: convert age in months to years,months,days

    because the show_date does not change the onChange event will not fire if attached to that field. you could on the otherhand attach to the dob of the animal field on change event then it should calculate when you enter the dob.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  11. #11
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: convert age in months to years,months,days

    okay I made changes to the form.
    now on change event in on date of birth field. tab order is changed so that the show date is filled in before tha dob is filled in.
    Attached Files Attached Files
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  12. #12
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: convert age in months to years,months,days

    if you think, you may need to change the show_date periodically on the data then you can have same function fire onChange event of that field too.
    you can modify the code for the function to skip calculation if either of the fields is empty. if you do that then you can keep the current tab order.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  13. #13
    Member
    Real Name
    Jim Doyle
    Join Date
    Dec 2006
    Location
    Krum, Texas
    Posts
    213

    Default Re: convert age in months to years,months,days

    The tab order in each example works fine. I never gave it a though that the tab order effected running the code. Learned something the last few days.
    This message board and it's advanced "Certified Alphaholic" are amazing.
    Again thinks again.
    Jim

Similar Threads

  1. Age if years, months and days
    By GGandhi in forum Code Archive
    Replies: 0
    Last Post: 01-18-2014, 10:50 AM
  2. how to convert months in to years and months?
    By richard2007 in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 12-19-2012, 06:51 AM
  3. Age in years and months
    By hsl9999 in forum Alpha Five Version 6
    Replies: 4
    Last Post: 10-20-2005, 10:01 PM
  4. Age in months and years
    By Edgar Lewis in forum Alpha Five Version 5
    Replies: 1
    Last Post: 02-01-2004, 09:16 PM
  5. age in months and years
    By Edgar Lewis in forum Alpha Five Version 5
    Replies: 3
    Last Post: 12-04-2002, 02:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •