SQL Date & Time Query Generator

Select a starting and ending date-time to build a SQL range condition for a DATETIME or TIMESTAMP column.

Select one or both date-time values.

SQL pattern

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.

PDO parameter binding

<?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
]);
?>



Subscribe to our YouTube Channel here



plus2net.com




SQL Video Tutorials










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer