Jump to content

How to calculate age


Erik.
 Share

Recommended Posts

Hello,

I have a big database whit people.

I want to know who is 16 years old, how to do that?

I know you can do that whit this year-age but that is not precisely enough.

example.

When it is 05-02-2007 Europe date

My birth day is at 06-02-1991

When i scan that person will say that he is 16 but he is tomorrow 16.

How to calculate that?

Gr Erik

I little problem, hard to find and fix

Link to comment
Share on other sites

_DateDiff()

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • 4 weeks later...

Hi,

I now want to add this option to my program..

Now do i have a little problem: in Europa we have the day format in DD/MM/YYYY and whit _DateDiff i need YYYY/MM/DD

How to fix it whitout changing my settings?

I little problem, hard to find and fix

Link to comment
Share on other sites

Hi,

I now want to add this option to my program..

Now do i have a little problem: in Europa we have the day format in DD/MM/YYYY and whit _DateDiff i need YYYY/MM/DD

How to fix it whitout changing my settings?

just do a string strip using the "/" as a delimiter and then rearrange

$datestring = "DD/MM/YYYY"
$newdatestring=StringSplit($datestring,"/")
msgbox(0,"here you go",$newdatestring[3] & "/" & $newdatestring[2] & "/" & $newdatestring[1])

cheers!

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

I have a little problem whit this script..

It now calculates the age of a person..

when i add someone and at the input of the birth day i full in a . then the program crash because it can not calculate..

But when it sees an error it needs to the this birth day: 0-0-0000 whit to do that?

I use the . when i did not made a card for a members and i need to add them to my program..

Could someone help me please.

I little problem, hard to find and fix

Link to comment
Share on other sites

Hi,

$bereken = StringSplit($string[7],"-")
                    $berekenen = _DateDiff("y",$bereken[3] & "-" & $bereken[2] & "-" & $bereken[1],_NowCalc())
                    GUICtrlSetData($personage2,$berekenen)
                    If $berekenen >15 Then
                        MsgBox(0,"Leeftijd","Persoon is:" & $berekenen & " en mag niet meer naar binnen")
                    Else
                    EndIf

This is the script..

it reads the age from a input normaly it is correct...

When i did not made a card for a person i need to add then past so i only full there first and lastname, you need to use all inputs:

firts name,lastname,streetname, city,age,telephone number

so i use the . so the program sees that i added data into a input..

But then it can not calculate the age and it crash..

Hope you understand

I little problem, hard to find and fix

Link to comment
Share on other sites

Here you have an example:

#include <Date.au3>


$input = InputBox("Leeftijd","geef uw geboorte datum op")
$bereken = StringSplit($input,"-")
$test = _DateDiff("y",$bereken[3] & "-" & $bereken[2] & "-" & $bereken[1],_NowCalc())
MsgBox(0,"",$test)

save it and take a try.. when you go the inputbox you full in you birth day DD-MM-YYYY when u only put a . into it you go an error..

How could you make it when you full in some other then the birth day then it automaticly full in 0-0-0000 ?

I little problem, hard to find and fix

Link to comment
Share on other sites

/ sorry stupid, my suggestion was wrong, must have done something wrong with test first time, doesn't seem to work.

so anyway, what exactly do you want, a function that checks if your date has been entered in the right format, or a function that also accepts dates with . as delimiter?

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Lol een nederlander das fijn:P

Mijn engels is heel slecht..

Ik had al aan zoiets zitten denken maar wist niet of dat wel ging vond het een rare error.

Dat werkt.

Nu heb ik een heel programma van 1300 regels en dat ga ik hier niet zomaar posten.

Als ik nu een . of iets invul hoe kan ik hem dan automatisch de volgende datum in laten vullen: 0-0-0000?

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$berekenen = _DateDiff("y",$bereken2[3] & "-" & $bereken2[2] & "-" & $bereken2[1],_NowCalc())

$berekenen = _DateDiff("y",^ ERROR

Edited by Erik.

I little problem, hard to find and fix

Link to comment
Share on other sites

save it and take a try.. when you go the inputbox you full in you birth day DD-MM-YYYY when u only put a . into it you go an error..

How could you make it when you full in some other then the birth day then it automaticly full in 0-0-0000 ?

Use StringIsDigit to check if it's numbers only.

Link to comment
Share on other sites

Who to lett it full in automaticly 0-0-0000 if it is not StringIsDigit?

This should work better: check $input for any characters other than ' - ' and digits.

#include <Date.au3>

$input = InputBox("Leeftijd","geef uw geboorte datum op")
If StringRegExp($input,"[^-0-9]",0) Then  ; <-- geeft 1 als er een ander character dan een - of een cijfer in staat
    MsgBox(0,"","De datum heeft het foute formaat.")

Else
    $bereken = StringSplit($input,"-")
    $test = _DateDiff("y",$bereken[3] & "-" & $bereken[2] & "-" & $bereken[1],_NowCalc())
    MsgBox(0,"",$test)
EndIf

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Hi,

I am trying this:

$leeftijd = GUICtrlRead($nonage)
                    
                    If StringRegExp($leeftijd,"[^-0-9]",0) Then ; <-- geeft 1 als er een ander character dan een - of een cijfer in staat
                    MsgBox(0,"","De datum heeft het foute formaat.")
                    GUICtrlSetData($nonage,"0-0-0000")
                    sleep(100)
                    Else
                    EndIf
                    $bereken2 = StringSplit($leeftijd,"-")
                    $berekenen = _DateDiff("y",$bereken2[3] & "-" & $bereken2[2] & "-" & $bereken2[1],_NowCalc())
                    If $berekenen >16 Then
                        MsgBox(0,"Leeftijd","Persoon is:" & $berekenen & " en mag niet meer naar binnen")
                    Else
                    EndIf

But it does not work...

I little problem, hard to find and fix

Link to comment
Share on other sites

$leeftijd = GUICtrlRead($nonage)
If StringRegExp($leeftijd, "[^-0-9]", 0) Then ; <-- geeft 1 als er een ander character dan een - of een cijfer in staat
    MsgBox(0, "", "De datum heeft het foute formaat.")
    GUICtrlSetData($nonage, "0-0-0000")
    Sleep(100)
Else
EndIf
$bereken2 = StringSplit($leeftijd, "-")
$berekenen = _DateDiff("y", $bereken2[3] & "-" & $bereken2[2] & "-" & $bereken2[1], _NowCalc())
If $berekenen > 16 Then
    MsgBox(0, "Leeftijd", "Persoon is:" & $berekenen & " en mag niet meer naar binnen")
Else
EndIf

But it does not work...
1) First you read an age from some GUICtrl. Then you check with my regexp line whether this age contains a 'non-date' character, and try a date calculation with it. I would presume that some age that you read is a number, not a date. Put a date in the $leeftijd (and rename it to $datum or something :whistle:) and this should work...

2) Next you set the GUICtrl $nonage to a date, but you don't re-read that new date (0-0-0000) into the variable so if one enters it in a wrong format, it keeps the same wrong format in the second part which is always executed no matter if you enter the right format. Suggestions: either don't execute the calculation as long as the date is not in the right format, or put 0-0-0000 in your date variable and do the calculation (but have a weird result - i would go with the first suggestion).

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Hi,

Yes that was what i am doing wrong:P

I already found it but that is always when i post something:P :whistle:

Hi, that works now.. you only can full numbers into it.. is there a way to check if it is right??? because i can full in 1111 and it accepts the term and then my program crash...

I need a - into it..

Edited by Erik.

I little problem, hard to find and fix

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...