How To Convert DATETIME data in One Field to Unix Timestamp and Add Results To New Field in MySQL Command Line

I have a self-hosted WordPress blog post that got popular and has over 100 comments. I decided to purchase a domain name and use the content from the post to build a single manually coded php page. This is something I do often, but always branch off using a separate WordPress install. Exporting / Importing the comments from the old post into the new one is simple. However, in this case, I decided to just manually code a simple index.php page.

For the comments, I decided to use GentleSource Comments. Comment data is stored in a MySQL database and it’s very lightweight compared to using WordPress. My goal was to then simply export the existing WordPress post comment data into the GentleSource Comments database. That process was easy. Basically, I snagged a copy of the wp_comments table and simply changed the field names to match the appropriate field names of what’s required in the GentleSource Comments database and removed unnecessary fields that were not native to the GentleSource Comments database structure.

Read More

The project is a success; however, I have one task left to do — to take all of the DATETIME entries from the comment_date field and convert that data to unix timestamp and add it into a new field labeled comment_timestamp.

I can easily do this manually line by line in phpMyAdmin, but I would rather do it quickly in mysql> thru a secure shell. The problem is I just can’t seem to figure out the command. Would someone mind helping me out?

Here are some screen shots that offer some visuals on what I am doing.

EDIT: I am a new user and need 10 reputation to post images. If you want to see the screen shots you are welcome to view them on my blog post here.

Related posts

Leave a Reply

1 comment