Select a starting and ending date-time to build a SQL range condition for a DATETIME or TIMESTAMP column.
SELECT *
FROM table_name
WHERE DATE_FIELD BETWEEN '2026-09-20 08:36:44'
AND '2026-09-20 18:28:36';
BETWEEN includes both endpoints. When your UI collects exact date-times, that behavior is usually intuitive. For whole-day searches, see date range queries and prefer a half-open next-day boundary.
<?php
$sql = 'SELECT * FROM table_name
WHERE DATE_FIELD BETWEEN :from_dt AND :to_dt';
$stmt = $dbo->prepare($sql);
$stmt->execute([
':from_dt' => $fromDateTime,
':to_dt' => $toDateTime
]);
?>
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.