78758

MySQL query for month year

Question:

I have a table with following fields

id (int) name (varchar) dob (datetime)

Now I need a query that can match month and year at same time

What I am using right now is

select * from users where month(dob)='12' and year(dob)='2010'

I don't want to use month() and year(), can it be done in single thing?

Help appreciated

Thanks

Answer1:

It can be expressed as you request, but I don't think it would be any more efficient.

where dob >= '2010-12-01' and dob <= '2010-12-31 23:59:59'

or

where '201012' = date_format(dob,'%Y%m')

Answer2:

select * from users where dob >= '2010-12-01' and dob < '2011-01-01'

Recommend

  • Returning a value at random based on a probability weights [duplicate]
  • Calculate age (with decimal places) in R
  • The parameterized query '' expects the parameter '', which was not supplied
  • Add base class to existing prototype chain so that instanceof works
  • Access SQL count number of people group by week number
  • Java String Date Validation Using Hibernate API
  • Serialize EF Object into JSON - ASP.NET MVC
  • laravel using twitter bootstrap and datepicker
  • How to post JSON to a REST webservice in codenameone
  • laravel 5.4 modify data before validation in request [closed]
  • Jackson: JSON parsing for array of parent elements : Root name '' does not match expected
  • How to enable Server Side search with jQuery dataTables?
  • How to filter ng-repeat value on clicking of checkbox field in angularjs?
  • Error: String or binary data would be truncated. The statement has been terminated
  • XPath expression with white space in node for defiant.js
  • The binary operator LessThan is not defined for the types 'System.Nullable`1[System.DateTime]&#
  • How do I make WIF use RSA15 when encrypting data using a certificate?
  • How to get list of users who's birthday is today in MongoDB
  • FlexJSON Orders Alphabetically by Default
  • How to use arithmetic operators with SAS macro variables [duplicate]
  • Find Previous month name using Calender or any classes that in java
  • Invalid Date on validation Date of js
  • MySQL Order by column = x, column asc?
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Can you perform a UNION without a subquery in SQLAlchemy?
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • Extracting HTML between tags
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Illegal mix of collations for operation for date/time comparison
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • TFS: Get latest causes slow project reloading
  • Updated Ionic CLI but shows previous version (Windows)
  • Display Images one by one with next and previous functionality
  • Comma separated Values
  • SQL merge duplicate rows and join values that are different
  • Trying to get generic when generic is not available
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Sorting a 2D array using the second column C++
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?