I am having issues comparing and updating times in PHP/MySQL

I am building a simple webapp in HTML, CSS, JS, PHP and MySQL. I am struggling currently with comparing dates and times. Basically, each user has an option to “bump” their listing every 2 hours, at the top of my PHP functions file I have: date_default_timezone_set('America/Toronto');. In my servers table I have a column called “last_bump” which updates to NOW(); when users bump their listing.

Not sure if this has anything to do with it, but my PC is in UTC-3:30 Newfoundland, but when I bump a listing, it starts the countdown saying 3h 29m 59s until I can bump again, which should only be +2 hours from last_bump.

Here is my code:

my-servers.php (PHP)

$lastbump = new DateTime($row['last_bump']);
                            $nextbump = new DateTime($row['last_bump']);
                            $nextbump->add(new DateInterval('PT2H'));

                            $currenttime = new DateTime();

                            if ($currenttime >= $nextbump) {
                                echo '<a href="#" class="btn btn-primary-sm" data-server-id="' . $row['id'] . '">Bump Server</a>';
                            } else {
                                // Calculate time difference in seconds
                                $timeDiff = $nextbump->getTimestamp() - $currenttime->getTimestamp();
                                echo '<div class="countdown text-center" data-time="' . $timeDiff . '"></div>';
                            }

my-servers.php (JS)

function startCountdown(element, time) {
            let countdownTime = time;

            const updateCountdown = () => {
                if (countdownTime > 0) {
                    countdownTime--;

                    const hours = Math.floor(countdownTime / 3600);
                    const minutes = Math.floor((countdownTime % 3600) / 60);
                    const seconds = countdownTime % 60;

                    // Create a readable countdown string
                    let countdownText = 'Next Bump: ';
                    if (hours > 0) {
                        countdownText += `${hours}h `;
                    }
                    if (minutes > 0 || hours > 0) {
                        countdownText += `${minutes}m `;
                    }
                    countdownText += `${seconds}s`;

                    element.innerText = countdownText;
                } else {
                    element.innerText = 'You can bump now!';
                    clearInterval(countdownInterval);
                    location.reload(); // Refresh the page to show the bump button
                }
            };

            updateCountdown(); // Initial call to display the timer
            const countdownInterval = setInterval(updateCountdown, 1000);
        }

        // Initialize countdown for each countdown element
        document.querySelectorAll('.countdown').forEach(element => {
            const time = parseInt(element.getAttribute('data-time'), 10);
            startCountdown(element, time);
        });

api/bump-server.php

include '../functions.php'; // Adjust path as per your file structure

// Ensure POST data exists and is JSON
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, true);

// Ensure JSON data was successfully decoded
if ($input === null) {
    http_response_code(400); // Bad request
    echo json_encode(array('error' => 'Invalid JSON data'));
    exit;
}

// Retrieve and sanitize server_id from JSON data
$server_id = isset($input['server_id']) ? intval($input['server_id']) : null;

if (!$server_id) {
    http_response_code(400); // Bad request
    echo json_encode(array('error' => 'Invalid server ID'));
    exit;
}

// Perform database update to set last_bump timestamp
$stmt = $conn->prepare("UPDATE servers SET last_bump = NOW() WHERE id = ?");
$stmt->bind_param('i', $server_id);

if ($stmt->execute()) {
    // Success response
    http_response_code(200); // OK
    echo json_encode(array('success' => true));
} else {
    // Error response
    http_response_code(500); // Internal server error
    echo json_encode(array('error' => 'Failed to update server bump'));
}

$stmt->close();

I tried adding a different column in my database table called next_bump but same issues.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật