dHumphrey
dHumphrey

Reputation: 307

How to get rows after a time of day using datetime column

I am running queries for a ticketing system. I want to extract all tickets created after 6:00PM or 18:00:00 in database/military time.

Could I use a DATEPART function or EXTRACT function?

Something like this may work:

SELECT *
FROM ticket
WHERE TIME IS AFTER 6PM

The issue is that the datetime format is as '2014-12-01 16:13:38' so I would need to specify for only the characters after the DATE section.

Upvotes: 1

Views: 409

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269583

In MySQL, just use the hour() function:

SELECT *
FROM ticket
WHERE hour(time) >= 18;

Upvotes: 3

Related Questions