Reputation: 59
I need to find out the records between AM and PM from the below table.
for eg: If I Enter START TIME AS 7.00 AM AND END TIME AS 4.00 PM, I need to get below records.
Start Time and End Time data is in varchar datatype with 12 hour format. How do i distinguish between AM and PM in the search criteria. Is there any inbuilt function to extract the time in 24 hour format in sql server?. Thanks in advance.
Upvotes: 0
Views: 387
Reputation: 31417
Convert your fields into time
format and then compare it.
SELECT CONVERT(time, '07:01 PM')
Now, you cane write your query like below
select * from yourtable where CONVERT(time, starttime) >= CONVERT(time, '07:00 AM') AND CONVERT(time, endtime) <= CONVERT(time, '04:00 PM')
Upvotes: 1