• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with age script

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey everyone,

I am trying to get an age script to work.

but it keeps failing, or when I think its working right I try random dates and it fails.

what am I doing wrong.



i tried a few thing, namely:
changing the flow & operands if the statements
changing the decrement position in the statement.

nothing seems to get this correct.

I know that I am looking for:
if my birth month is less than or equal to this month AND
if my date of birth is equal to or less than today
then I am one year older

but it does not work

how can I sort this?

ik
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first thing I would do if I were debugging this script would be to create an alert statement that prints shows me all the values being compared in this line

to make certain that the values being compared are what I think they are.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I were you, I would take the two date objects and subtract the one from the other. That will give you miliseconds. Do a simple division and you got age.

Eric
 
Ranch Hand
Posts: 249
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe your problem is in


You only care about the date if the months are equal. But what if the birth day is 11/29 and today is 12/01. birth.getMonth() <= today.getMonth() translates to true, but birth.getDate() <= today.getDate() translates to false. I suggest using some different ifs



Hopefully that can help.
 
Davy Kelly
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops....

my problem was I was passing in the months as jan = 1 when it should be 0.

so I changed my script a wee bit, and took one away from the months

ik

edit:
this is my script now

I get the date of birth from a form...



[ January 16, 2008: Message edited by: Davy Kelly ]
[ January 16, 2008: Message edited by: Davy Kelly ]
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic