how to convert date of birth in words in php?

how to convert date of birth in words in php and how to extract and format the date and time using the PHP date and time functions.

Convert birth date to words in PHP

Learn Convert birth date to words in PHP starting from this is a overview, Some Screen shot, Example, Demo. convert DOB into proper word format using PHP Example : how to convert date of birth in words in php?

index.php

<?php
function translate_names($num)
{ 

$ones = array(
0 =>"ZERO", 
1 => "ONE", 
2 => "TWO", 
3 => "THREE", 
4 => "FOUR", 
5 => "FIVE", 
6 => "SIX", 
7 => "SEVEN", 
8 => "EIGHT", 
9 => "NINE",
10 => "TEN", 
11 => "ELEVEN", 
12 => "TWELVE", 
13 => "THIRTEEN", 
14 => "FOURTEEN", 
15 => "FIFTEEN", 
16 => "SIXTEEN", 
17 => "SEVENTEEN", 
18 => "EIGHTEEN", 
19 => "NINETEEN",
"014" => "FOURTEEN" 
); 
$tens = array( 
0 => "ZERO",
1 => "TEN",
2 => "TWENTY", 
3 => "THIRTY", 
4 => "FORTY", 
5 => "FIFTY", 
6 => "SIXTY", 
7 => "SEVENTY", 
8 => "EIGHTY", 
9 => "NINETY" 
); 
$hundreds = array( 
"HUNDRED", 
"THOUSAND",
"MILLION", 
"BILLION", 
"TRILLION",
"QUARDRILLION" 
); /* limit t quadrillion */
$num = number_format($num,2,".",",");
$num_arr = explode(".",$num); 
$wholenum = $num_arr[0]; 
$no_of_dordr = $num_arr[1]; 
$whole_arr = array_reverse(explode(",",$wholenum)); 
krsort($whole_arr,1); 
$response_txt = ""; 
foreach($whole_arr as $key => $i){
	
while(substr($i,0,1)=="0")
		$i=substr($i,1,5);
if($i < 20){ 
/* echo "getting:".$i; */
$response_txt .= $ones[$i]; 
}elseif($i < 100){ 
if(substr($i,0,1)!="0")  $response_txt .= $tens[substr($i,0,1)]; 
if(substr($i,1,1)!="0") $response_txt .= " ".$ones[substr($i,1,1)]; 
}else{ 
if(substr($i,0,1)!="0") $response_txt .= $ones[substr($i,0,1)]." ".$hundreds[0]; 
if(substr($i,1,1)!="0")$response_txt .= " ".$tens[substr($i,1,1)]; 
if(substr($i,2,1)!="0")$response_txt .= " ".$ones[substr($i,2,1)]; 
} 
if($key > 0){ 
$response_txt .= " ".$hundreds[$key]." "; 
} 
} 
if($no_of_dordr > 0){ 
$response_txt .= " and "; 
if($no_of_dordr < 20){ 
$response_txt .= $ones[$no_of_dordr]; 
}elseif($no_of_dordr < 100){ 
$response_txt .= $tens[substr($no_of_dordr,0,1)]; 
$response_txt .= " ".$ones[substr($no_of_dordr,1,1)]; 
} 
} 
return $response_txt; 
} 

if(isset($_POST['convert']))  
{
$birth_date = $_POST[birth_date];
$new_birth_date = explode('-', $birth_date);
$year = $new_birth_date[0];
$month = $new_birth_date[1];
$day  = $new_birth_date[2];
$birth_day=translate_names($day);
$birth_year=translate_names($year);
$monthNum = $month;
$dateObj = DateTime::createFromFormat('!m', $monthNum);//Convert the number into month name
$monthName = strtoupper($dateObj->format('F'));
echo "<p align='center' style='color:blue'>$birth_day $monthName $birth_year</p>";
}
?>
<!DOCTYPE html>
<html>
	<head>
		<title>Conver Birth date to Words in PHP</title>
	</head>
	<body>
		<form method="post">
			<table border="0" align="center">
				<tr>
				<td>Enter Your Numbers</td>
				<Td><input type="text" name="birth_date" /></Td>
				</tr>
				<tr>
				<td colspan="2" align="center">
				<input type="submit"  name="convert"/>
				</td>
				</tr>
			</table>
        </form>

	</body>
</html>

php date of birth to age

Read Also:  Woocommerce list product attributes

php get age from data_of_birth : Simple php function for calculating Age from data_of_birth: $_age = floor((time() – strtotime(‘1986-09-16’)) / 31556926); 31556926 is the number of seconds in a year.

calculate person age by birthdate php using : how to convert date of birth in words in php?

 public function getAge($date)
    {
        
        $data_of_birth = new DateTime($date);
        
        $now = new DateTime();
         
        $difference = $now->diff($data_of_birth);
         
        $age = $difference->y;
         
        return  $age;
    }

age php datetime

function get_age( $date ) { 
    $age = date('Y') - $date; 
   if (date('md') < date('md', strtotime($date))) { 
       return $age - 1; 
   } 
   return $age; 
} 

Convert YYYY-MM-DD date to text

date("M jS, Y", strtotime("2021-08-09"));

PHP: Converting date into words on Localhost (how to convert date of birth in words in php?)

Using strtotime and date combination in PHP:

convert date of birth in words
convert date of birth in words

function numberTowords($eng) {
    $names = array (
      'Januari' => 'January',
      'Februari' => 'February',
      'Maart' => 'March',
      'April' => 'April',
      'Mei' => 'May',
      'Juni' => 'June',
      'Juli' => 'July',
      'Augustus' => 'August',
      'September' => 'September',
      'Oktober' => 'October',
      'November' => 'November',
      'December' => 'December',
);

    return array_search($eng, $names);
}

$date = $nextup['date'];
$month = addcslashes(numberTowords(date('F', strtotime($date))), 'a..zA..Z');

$string = "d $month Y H:i:s";
echo date($string, strtotime($date));