CGRRay Posted January 25, 2008 Share Posted January 25, 2008 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? Quote Link to comment Share on other sites More sharing options...
fenway Posted January 25, 2008 Share Posted January 25, 2008 So from DB to DB? Quote Link to comment Share on other sites More sharing options...
CGRRay Posted January 25, 2008 Author Share Posted January 25, 2008 I'm using mysql 5.0.45 and php 5.1.4 Yes, both tables are in the same db. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 25, 2008 Share Posted January 25, 2008 How about an INSERT INTO... SELECT WHERE... using FROM_UNIXTIME? Quote Link to comment Share on other sites More sharing options...
CGRRay Posted January 25, 2008 Author Share Posted January 25, 2008 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 25, 2008 Share Posted January 25, 2008 Glad to hear it! Always appreciated when solutions are posted, too. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.