djokerndthief
djokerndthief

Reputation: 455

MySQL: Trying to get Current date with current hour, without minutes and seconds

I am trying this:

SELECT matchId FROM Matches where matchDate = CURRENT_DATE + HOUR(CURRENT_TIME) + ':00:00'

but cant get it to work. When I manually do this, it works:

SELECT matchId FROM Matches where matchDate = '2018-01-31 16:00:00'

I tried many variations of, containing CURDATE(), CURRENT_DATE, etc... What am I doing wrong?

Upvotes: 2

Views: 3414

Answers (2)

Josh Adams
Josh Adams

Reputation: 2099

You could just use NOW()

SELECT matchId FROM Matches where matchDate = DATE_FORMAT(NOW(), "%y-%m-%d %h:00:00");

Upvotes: 2

Ravi
Ravi

Reputation: 31417

You could use DATE_FORMAT, with %Y-%m-%d for date and %H for hours.

SELECT DATE_FORMAT(NOW(), "Date : %Y-%m-%d Hour : %H")

It returns

Date : 2018-01-31 Hour : 15

Upvotes: 2

Related Questions