How to convert MSSQL date format to MySQL

I recently had to transfer over some databases from MSSQL Server 2000 to MySQL. Unfortunately, the date format that MSSQL keeps is MM-DD-YYYY HH:MM:SS am/pm. MySQL uses YYYY-MM-DD HH:MM:SS (24hour format). For example, 8/14/2007 5:00:00 PM (MSSQL format) and 2007-08-14 17:00:00 (MySQL format). In MySQL, we can use the date_format(). But what is the equivalent for MSSQL? That would be the CONVERT(). This is how you would use it.

Here’s the query to run on MSSQL:

SELECT CONVERT(VARCHAR(40),[date_column_name],120) AS new_date_format FROM [table_name]

The “new_date_format” is the column name that will display the MySQL formatted date. This should also work if you have a column that stores datestamp and a column that stores timestamp.

You can find a list of expression values from http://msdn2.microsoft.com/en-us/library/ms187928.aspx. Hope this helps somebody.

One thought on “How to convert MSSQL date format to MySQL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s