Jump to content

[SOLVED] Replacing UNIX timestamp with MYSql timestamp


Recommended Posts

I inherited a database that has a table of registration dates in unix format, for example 1200590610

, I want to change these dates to mysql timestamp format and insert them into a new table. I have a PHP script that does the conversion

<?php

$intime = (1200590610);

$read_in = date("Y-m-d H:i:s", $intime);

?>

The original table (members) has 3 fields: fn, ln, reg_date. reg_date is in unix format. I want to select the record, convert the date and insert it into a new table (mem) with the same 3 fields.

Can you help?

Just wanted to post what I used so others might benefit.

Your suggestion worked. Here's the code:

 

INSERT INTO new date(member_id,user_id,member_number, fn, joined,renewed,expires)

SELECT member_id, user_id, member_number, fn, FROM_UNIXTIME(joined), FROM_UNIXTIME(renewed), FROM_UNIXTIME(expires) FROM old_date;

 

Thanks for the help. Ireally appreciate it and I learned a lot getting this to work.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.