C#
C++
SQL

0 Comments:

Post a Comment



<< Home

Date formatting using MySQL

By default MySQL stores its dates in 'YYYY-MM-DD HH:MM:SS' format. When you have to integrate with .NET, it's nice to get the date in a format which is readable by DateTime.Parse().

In your SQL query, you can format the date by using the date_format function.
SELECT date_format(YourDateHere, '%a %D %b %Y') FROM TableName;
Here are some example formatting strings and examples of their output (replace the formatting in the red part of the query above).

ExampleFormat String
1/28/2008'%c/%e/%Y'
01/28/2008'%m/%d/%Y'
1/28/2008 12:30'%c/%e/%Y %H:%i'
01/28/2008 12:30'%m/%d/%Y %H:%i'
1/28/2008 12:30:59'%c/%e/%Y %T'
01/28/2008 12:30:59'%m/%d/%Y %T'

Labels: ,

posted by Brian at