Diasline Diasline - 1 year ago 83
MySQL Question

Select month from datetime column

I have a table that has a datetime column named :completed_date (2016-05-27 04:08:53). I would like to select all data for this current month while ignoring the time. Something like this:

$query = mysqli_query($dbc, " select * from eob_posting where

How can i remove the time so that the clause where considere only the date ?

Answer Source

Even shorter than the other answers :-)

Note that a datetime is basically also a string of the form "2016-01-01 12:34:56", so you can just:

> SELECT LEFT(NOW(), 7) as YearAndMonth;

So your query is easily expressed as:

SELECT * FROM eob_posting
WHERE LEFT(completed_date, 7) = LEFT(NOW(), 7)

Happy hunting!

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