Skip to content

Instantly share code, notes, and snippets.

@ericclemmons
Created April 8, 2010 18:25
Show Gist options
  • Save ericclemmons/360355 to your computer and use it in GitHub Desktop.
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
-- @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);
@ericclemmons
Copy link
Author

Assumes the name of the table is responses and the response_date is of DATETIME type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment