Change Date Format on Import to MySQL from CSV File

September 2, 2015 (5 years ago)

You have a .csv file with a date column that is formatted like this:  12/1/2015 (‘m/d/Y’).

You need to import it into a MySQL database DATE field named “my_dates”.

A straight import will result in all your dates showing up as ‘0000-00-00’, because MySQL uses the format ‘Y-m-d’, and won’t translate it natively.

Here’s the solution:

Create a VARCHAR field named “my_text_dates” in the database, and import the dates there.

Then, run this query:

UPDATE my_table SET my_dates = STR_TO_DATE(my_text_dates, '%m/%d/%Y')

Then, just delete the “my_text_dates” field, and you’re all set!

NOTE: the ‘%m/%d/%Y’ portion of the update statement needs to match exactly the format of your text date field.

Database Maintenance

October 17, 2014 (6 years ago)
WordPress, Database

WordPress automatically deletes items you have trashed (posts, pages, etc) after 30 days. You can set this to fewer days to keep them from building up.

Put this in your wp-config.php file:

define( 'EMPTY_TRASH_DAYS', 5 ); // 5 days


Limiting Revisions

October 17, 2014 (6 years ago)
WordPress, Database

To keep your database from bloating with endless revisions, you can limit the number that’s stored for each post.

Put this in your config.php file. (The second parameter is the number of revisions to keep.)

define( 'WP_POST_REVISIONS', 2 );


Skip to toolbar