my data is presented in datetime format how do i compare time and datetime in sql?

What you need to do is apply the TIME function to your activitytime column and then compare it to 12:00:00 and 16:00:00:

TIME(activitytime) BETWEEN '12:00:00' AND '16:00:00'

Note if you don’t want to include 16:00:00 replace that with 15:59:59. Also, if you write the time strings in HH:mm:ss format then you don’t need to apply TIME to them and can just compare directly.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top