gijew Posted April 14, 2008 Share Posted April 14, 2008 I was having trouble performing queries using unix timestamps (which is my preferred method - just getting that out of the way) so I felt like going old school and using the datetime field type in MySQL for this project. My problem is that I want to query MySQL to return a specific date (month / year). Here's what I have: :: Example data 2008-04-12 23:27:21 2008-04-13 00:12:10 2008-03-12 00:49:28 2007-12-25 13:14:15 :: Searching for 04-2008 It should return record 1 & record 2. I could post my query but I already know I'm way off so I'm not going to embarass myself further How would one go about doing this? I tried returning something with DATE_FORMAT (created_on, '%M %Y) and even a few variations of the DATE function inside of MySQL but it's returning nothing as I'm obviously missing something here. Suggestions? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 14, 2008 Share Posted April 14, 2008 The quickest query would be to just test the month and year of the date against the month and year you are searching for, rather than to run the date in each row through the format function - :: Searching for 04-2008 WHERE YEAR(created_on) = 2008 AND MONTH(created_on) = 4 Quote Link to comment Share on other sites More sharing options...
gijew Posted April 14, 2008 Author Share Posted April 14, 2008 Okay, I'm done programming for the night. That was too easy. I knew that Thank you for pointing my tired eyes in the right direction, lol. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.