Query MySQL Table For Records Changed Between Time Period

Goal: Search all users who were updated between a certain time period (in our case one day).

Scenario: A system wide glitch caused a set of users to have all of their last names changed to Smith. Your manager wants to know how many records are affected.

MySQL offers 2 or more ways this can be accomplished. First using <= and >=  the second using BETWEEN operator.

The between operator is identical to >= and <= and is inclusive. Notice the difference in order between the 2 queries.

In order for this query to work the field must be either datetime, timestamp, or date. If using date then remove the time portion from the query.

Demo on SQL Fiddle.

Share this Story
Load More Related Articles
  • PHP Programming

    PHP Type Hinting Arrays Using The Splat Operator

    It’s possible to type hint an array (sort of) in PHP without using a Doc block. Version 5.6 added a splat ...
  • Laravel

    Laravel Upgrade Considerations and Tips

    Laravel claims estimated upgrade times upgrading version to version, but this estimation may not be true for you. Upgrades take time ...
  • PHP

    Using array_reduce to Transform Data

    First, why we might transform data? If we have raw data from a database and need to send data to an ...
  • Programming

    Selecting Your Next App Dependency

    We often turn to open source or proprietary packages for adding functionality to our apps. Here are some key points and questions to ask when selecting your next dependency.
  • Tips


    As developers we work with non-technical people and we can do a better job connecting with them. Non-technical people don’t care ...
  • Life Pro Tip Tips

    Mental Snapshots

    Think back to a time where you accomplished something you had no idea how to do or when you accomplished something ...
Load More By Nick Escobedo
Load More In How-To's

Check Also

PHP Type Hinting Arrays Using The Splat Operator

It’s possible to type hint an array (sort ...