Feign Feign - 1 year ago 86
SQL Question

How to convert a mysql datetime column to just date?

Here is an explanation of how my table is set up (in sqlfiddle)

Basically, I have two columns. One is a varchar and contains a name. The other is a datetime and contains a certain date with a time.

I want to select rows where the date in the datetime matches today's date. I have tried things like...

select * from alerts_to_send where date_to_send = now()
select * from alerts_to_send where date_to_send = curdate()

I'm not exactly where to go from here... Any ideas would be greatly appreciated :)

Just to re-clarify, I want to select the rows where today's date matches the date part of my datetime type column.

Answer Source

try this

  select * from alerts_to_send 
  where  DATE_FORMAT(date_to_send,'%m-%d-%Y') = DATE_FORMAT(now(),'%m-%d-%Y')


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download