how to get the age by inserting the bithdate
Hello guys ,
I am working on php nowadays so i thought i would share this little snippet with you all . So here goes
this calculates the age when inputting the birthdate.
change it by changing the order
of "list($d,$m,$Y)".
An example on using it:
Hope this helped you
thank you
edit - subject changed
I am working on php nowadays so i thought i would share this little snippet with you all . So here goes
this calculates the age when inputting the birthdate.
Code: Select all
Day-Month-Year format. You can function getAge( $p_
strDate ) {
list($d,$m,$Y) = explode
("-",$p_strDate);
return( date("md") < $m.$
d ? date("Y")-$Y-1 : date("Y")
-$Y );
}
change it by changing the order
of "list($d,$m,$Y)".
An example on using it:
Code: Select all
done ! <?php
echo getAge("1-1-2000");
function getAge( $p_
strDate ) {
list($d,$m,$Y) = explode
("-",$p_strDate);
return( date("md") < $m.$
d ? date("Y")-$Y-1 : date("Y")
-$Y );
}
Hope this helped you
thank you
edit - subject changed
Find my programs on Softpedia
is this post helped you ? Why i am asking because if you guys interested i can make more tutorials . So what ?
Find my programs on Softpedia
nice going
never new this thx.
never new this thx.
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
How about this?
Code: Select all
Dim year As Integer = Today.Year - 1997
Dim month As Integer = Today.Month - 9
Dim day As Integer = Today.Day - 10
If month < 1 Then
year -= 1
month += 12
End If
If day < 1 And month = 1 Or month = 3 Or month = 5 Or month = 7 Or month = 8 Or month = 10 Or month = 12 Then
month -= 1
day += 31
ElseIf day < 1 And month = 4 Or month = 6 Or month = 9 Or month = 11 Then
month -= 1
day += 30
ElseIf day < 1 And month = 2 Then
month -= 1
day += 28
End If
MsgBox("You are " & year & " years, " & month & " months, and " & day & " days old.")
Or:
Code: Select all
The simplest would be Dim birthdate As DateTime = New Date(1998, 3, 10)
Dim totDays As Integer = (DateTime.Now - birthdate).TotalDays
Dim years As Integer = totDays \ 365
Dim days As Integer = totDays Mod 365
Dim months As Integer = days \ 30
days = days Mod 30
MessageBox.Show(years.ToString() + " years, " + months.ToString() + " months, " + days.ToString() + " days old.")
Code: Select all
MessageBox.Show(((DateTime.Now - Birthdate).Days / 365.0).ToString() + " years old.")
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
But that doesn't take into consideration months that have 31 or 28 days, does it?
Nope, just for 30 day months, which would be somewhat the average of the months
Edit:
Edit:
Code: Select all
Dim Age As DateTime = New DateTime((DateTime.Now - Birthday).Ticks)
MessageBox.Show(Age.Year.ToString() + " years, " + Age.Month.ToString() + " months, " + Age.Day.ToString() + " days.")
Last edited by MrAksel on Tue Jun 26, 2012 3:22 pm, edited 1 time in total.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Oh ok. Well the code i posted takes care of 30-day, 31-day and 28-day months
Edited Last post considers 31 & 28 days months
Edit: Nevermind, I realized its not working
Edit: Nevermind, I realized its not working
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Copyright Information
Copyright © Codenstuff.com 2020 - 2023