Hi All , we have requirement to select query with between date with time ?
For eg : '2025-02-01 11:01:48' and '2025-02-07 16:50:08' Will have 10 Records
'2025-02-01 11:01:48' and '2025-02-07 16:50:08' if its date wise -> will have 50 Records . we need to have accoding to date with time .
Desired Result -> 10 Records
Thanks in advance
Karthik.K

Jignesh KumarPosted Mar 4, 2025, 4:08 AM
Hello Karthik,
Please use this query and do require changes for your tables and columns,
Sreenath KappoorPosted Mar 4, 2025, 4:08 AM
Hi Karthik,
When you filter by just the date, you are essentially ignoring the time component, which can result in a higher number of records. To accurately filter by both date and time, you need to query using the full datetime values.
Ex: created_on of type DATETIME
you should use:
-- This query considers both date and time
SELECT *
FROM your_table
WHERE created_on BETWEEN '2025-02-01 11:01:48' AND '2025-02-07 16:50:08';
-- This query ignores time, only comparing dates
-- extracts only the date part, would ignore the time component and may return more records
SELECT *
FROM your_table
WHERE DATE(created_on) BETWEEN '2025-02-01' AND '2025-02-07';
Sangeetha SPosted Mar 3, 2025, 7:02 AM
To select records between specific dates and times in SQL, you can use the
BETWEENoperator along with your date-time values. Here's how you can structure your SQL query to achieve the desired result of retrieving records within a specific date and time range:BETWEENoperator includes both endpoints, so records that fall exactly on the start and end datetime will also be included.Sophia CarterPosted Mar 3, 2025, 3:59 AM
It sounds like you have a specific requirement for selecting records based on a date range that includes both the date and time components. To achieve this in SQL, you can use a query similar to the following:
This query will retrieve records from "your_table" where the "your_date_column" falls within the specified date and time range. By including the time component in the BETWEEN clause, you can ensure that the query considers both date and time for filtering the results.
In your scenario, you mentioned that selecting records purely based on dates would return 50 records, but you desire only 10 records based on the date and time range. By incorporating the time component in your query as shown above, you should be able to achieve the desired result of retrieving only 10 records that fall within that specific date and time range.
If you have a different table structure or specifics, feel free to provide more details for a more tailored example or explanation. Let me know if you need further assistance!