NYCPHP Meetup

NYPHP.org

[nycphp-talk] how to correct wrong mysql datetime columns?

David Mintz david at davidmintz.org
Tue Dec 2 12:55:54 EST 2008


I love answering my own questions (no sarcasm intended).

SELECT timestampdiff(SECOND, '1993-03-03 18:40:05', '2008-12-02 09:20:05');

Answer: 497025600

UPDATE your_table set created = date_add(created, INTERVAL 497025600 SECOND)
WHERE year(created) = 1993;

If anyone sees anything worth commenting please feel free. Otherwise, case
closed, just thought I'd post an answer for the record.

On Tue, Dec 2, 2008 at 10:45 AM, David Mintz <david at davidmintz.org> wrote:

> This isn't necessarily PHP but... close enough? You could script a solution
> in PHP and indeed I might.
>
> I had two CentOS servers' date info somehow go bad over the weekend. When I
> came back to work they thought it was 1993, wreaking havoc with the
> PHP/MySQL application hosted thereon. I restarted ntpd and they are now
> apparently doing fine, thanks. But I have some tables where the record
> creation date is saved using MySQL's  now(). There are now some rows with
> the wrong value in this field and I am not quite clever enough to see the
> best way to fix.
>
> The last output I have from the 'date' command before it was corrected is
> Wed Mar  3 18:40:05 EST 1993. When we got back to the present, 'date' said
> Tue Dec  2 09:20:05 EST 2008. Should I convert both to Unix timestamps,
> subtract the smaller from the larger and add that number of seconds to the
> values that I know are wrong? btw I know this number won't be exact but
> close enough will do, there being no alternative AFAIK.
>
> Gratefully,
>
> --
> David Mintz
> http://davidmintz.org/
>
> The subtle source is clear and bright
> The tributary streams flow through the darkness
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20081202/ec736cd9/attachment.html>


More information about the talk mailing list