<?php
 include ('connection.php') ;
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Function to get AM/PM
function getAmPm($time) {
    // Convert the time string to a DateTime object
    $dateTime = DateTime::createFromFormat('H:i', $time);

    // Check if the conversion was successful
    if ($dateTime === false) {
        return "Invalid time format";
    }

    // Format the DateTime object to get the AM/PM value
    $amPm = $dateTime->format('A');

    return $amPm;
}

// Query to get the time value from the database
$sql = "SELECT appointment_time FROM appointment_details WHERE appointment_id = '19'"; // Adjust your table and column names accordingly
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Fetch the row
    $row = $result->fetch_assoc();
    $time = $row['appointment_time'];

    // Determine AM/PM
    $amPm = getAmPm($time);
    echo $time . " is in the " . $amPm . "\n";
} else {
    echo "No time value found.";
}

// Close the database connection
$conn->close();
?>
