Menus

Showing posts with label Calculating Age from Birthdate. Show all posts
Showing posts with label Calculating Age from Birthdate. Show all posts

Thursday 20 December 2018

Calculating Age from Birthdate


Calculate age from given birthdate


How to Calculate Age from Date of Birth in PHP



<?php

$dateOfBirth = "21-12-1983";
$today = date("Y-m-d");
$diff = date_diff(date_create($dateOfBirth), date_create($today));
echo 'Age is '.$diff->format('%y');

?>




VB6 Code

Function Age (varBirthDate As Variant) As Integer 

 Dim varAge As Variant 

 If IsNull(varBirthdate) then Age = 0: Exit Function 

 varAge = DateDiff("yyyy", varBirthDate, Now) 
 If Date < DateSerial(Year(Now), Month(varBirthDate), _ 
 Day(varBirthDate)) Then 
 varAge = varAge - 1 
 End If 
 Age = CInt(varAge) 

 End Function