You are here -> Home > Developer Center > Handling Dates in MySQL

Handling Dates in MySQL
By: Jason Nowicki This article has been viewed 844 times.

   Date formats in MySQL are not the same as they are in MS SQL or Access. In MySQL, by default, dates are in this format: yyyymmdd. In order to handle this in .Net you need to format your dates using a String.Format function like this:

String.Format("{0:yyyyMMdd}", now)

This will give you the date in the format that is accepted by MySQL. You may also add '/' or '-' to your dates without any errors, like this:

String.Format("{0:yyyy/MM/dd}", now)

or

String.Format("{0:yyyy-MM-dd}", now)

Anything other than those two characters and you'll get an error from MySQL.

 

How helpful was this article?