Successfully fetch "wdate" from MySQL and print the date in format Y:m:d H:i:s, my goal is to input "wdate" in the second code "function" is this possible or completely wrong?
<?php 
$sql = "SELECT wdate, DATE_FORMAT(wdate,'%Y/%m/%d %H:%i:%s') AS wdate 
            FROM watering
            ORDER BY id 
            DESC limit 1";
$result = $conn->query($sql);
    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
$recoredDate = $row["wdate"];
            }
    } else {
      echo "<h1><b>Database is empty</b></h1>";
    }
?>
This is the second part calculating the difference like this:
<?php
 function time_elapsed_string($datetime, $full = false) {
    $now = new DateTime;
    $ago = new DateTime($datetime);
    $diff = $now->diff($ago);
    $diff->w = floor($diff->d / 7);
    $diff->d -= $diff->w * 7;
    $string = array(
        'y' => 'year',
        'm' => 'month',
        'w' => 'week',
        'd' => 'day',
        'h' => 'hour',
        'i' => 'minute',
        's' => 'second',
    );
    foreach ($string as $k => &$v) {
        if ($diff->$k) {
            $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
        } else {
            unset($string[$k]);
        }
    }
    if (!$full) $string = array_slice($string, 0, 1);
    return $string ? implode(', ', $string) . ' ago' : 'just now'; }    ?>  
   <?php echo ($recoredDate);?> <!-- Result from Database -->
 <?php echo time_elapsed_string('2021-01-28 20:46:25'); ?> <!-- Result from function -->
 
     
    