WebWork Magazin - Webseiten erstellen lassen, Online Medien, html

Webhoster, Webhosting Provider und Domain registrieren

Home | Registrieren | Einloggen | Suchen | Aktuelles | GSL-Webservice | Suleitec Webhosting
Reparatur-Forum | Elektro forum | Ersatzteilshop Haushalt und Elektronik


Homepage und Webhosting-Forum

Scripte und Programme für PHP, MYSQL. Diskussionen zur Programmierung im Web. Fragen zu CMS, Blogsoftware, Shops, Newsletter und vielen weiteren Scripten.


Forum » PHP & MySQL » Probleme bei der Altersangabe » Antworten
Benutzername:
Passwort: Passwort vergessen?
Inhalt der Nachricht: Fett | Kursiv | Unterstrichen | Link | Bild | Smiley | Zitat | Zentriert | Quellcode| Kleiner Text
Optionen: Emailbenachrichtigung bei Antworten
 

Die letzten 5 Postings in diesem Thema » Alle anzeigen
von DreamPromise
Hi

Genau was ich gesucht hab.
1000 Dank
von Philipp Gérard
gerade gefunden:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12:
<?php
$day_of_birth = "15.03.1957";

$array = explode(".",$day_of_birth);
$seconds_since_birth = mktime(0,0,0,$array[1],$array[0],$array[2]);
$today = time();

$age = $today - $seconds_since_birth;
$age_in_years = date("Y",$age) - 1970;

echo $age_in_years;
?>
von DreamPromise
Hi Leute
Ich konnte das Problem nicht lösen.Aber vielleicht ihr ?
Auf ein Posting von mir vor einigen Tagen hat man mir irgendwie nicht so richtig weitergeholfen.

Vielleicht kann sich ja nochmal jmd erbarmen

Folgender Code sollte mir anzeigen wie alt derjenige ist, dessen Geburtsdatum (z.B. 17.11.1960) in der Tabelle steht.

<?php

function ger2enDate($date)
{
$date = explode(".", $date);
$date = $date[2]."-".$date[1]."-".$date[0];
return $date;
}

function getAge($birthday)
{
$today = getdate();
$birthday = explode("-", $birthday);

$birth_day = $birthday[2];
$birth_month = $birthday[1];
$birth_year = $birthday[0];

$today_day = $today["mday"];
$today_month = $today["mon"];
$today_year = $today["year"];

if (substr($birth_day, 0, 1) == "0")
$birth_day = substr($birth_day, 1, 1);
if (substr($birth_month, 0, 1) == "0")
$birth_month = substr($birth_month, 1, 1);
if (substr($birth_year, 0, 1) == "0")
$birth_year = substr($birth_year, 1, 1);
if (substr($today_day, 0, 1) == "0")
$today_day = substr($today_day, 1, 1);
if (substr($today_month, 0, 1) == "0")
$today_month = substr($today_month, 1, 1);
if (substr($today_year, 0, 1) == "0")
$today_year = substr($today_year, 1, 1);

if ($today_month > $birth_month)
$age = $today_year - $birth_year;
if ($today_month == $birth_month) {
$age = $today_year - $birth_year;
if ($today_day < $birth_day)
$age--;
}
if ($today_month < $birth_month)
$age = ($today_year - $birth_year) -1;

return $age;
}

$db_server = "www.jensschmelzer.info";
$db_name = "v035212";
$db_user = "v035212";
$db_passwort = "********************";

$db = @MYSQL_CONNECT($db_server,$db_user,$db_passwort) or die ("Konnte keine Verbindung zur Datenbank herstellen");
$db_check = @MYSQL_SELECT_DB($db_name);

$query = mysql_query("SELECT * FROM benutzer LIMIT 1",$db);
$row = mysql_fetch_row($query);

$alter = getAge(ger2enDate($row[1]));

echo $alter;

mysql_close($db);

?>

Hier könnt ihr das Ergebnis sehen

Nach oben