Jump to content

SELECT month and year FROM datetime


Call-911

Recommended Posts

Hello All,

 

I have a datetime column. I'm making an archive, and I need to query the database to get all results from a specific month and year.

 

I can get all results from a year by doing:

 

SELECT *

FROM news

WHERE show = 'true' AND date LIKE '%2011%'

ORDER BY date desc, id2 desc

 

But if I try to add in the month

 

SELECT *

FROM news

WHERE show = 'true' AND date LIKE '%2011-01%'

ORDER BY date desc, id2 desc

 

it doesn't work.

 

Any thoughts, or any idea how to get results from the datetime using just the month and date?

Link to post
Share on other sites
  • 4 months later...

Give this a try:

 

SELECT *

FROM news

WHERE show = 'true' AND YEAR(date) = 2011 AND MONTH(date) = 1

ORDER BY date desc, id2 desc

 

 

Hope that helps.

 

-Brian

 

Can this be used to get the Hours and Minutes separately from the time ?? I mean something like "Hours(time) = 10"  :-\

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.