Jump to content

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
https://forums.phpfreaks.com/topic/226980-select-month-and-year-from-datetime/
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"  :-\

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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