Created
April 8, 2010 18:25
-
-
Save ericclemmons/360355 to your computer and use it in GitHub Desktop.
Update a table's responses' datetimes so that all records have occurred recently
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- @last = the very last response | |
SELECT @last:=UNIX_TIMESTAMP(response_date) FROM responses GROUP BY response_date DESC LIMIT 1; | |
-- @diff = how much time has passed since the last response | |
SELECT @diff:=(UNIX_TIMESTAMP() - @last); | |
-- Add the date difference to all responses to chronologically bring them up to date | |
UPDATE responses SET response_date=FROM_UNIXTIME(UNIX_TIMESTAMP(response_date) + @diff); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes the name of the table is
responses
and theresponse_date
is of DATETIME type.