Jump to content

SELECT month and year FROM datetime


Call-911
 Share

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 comment
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 comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.