Format Date
-
Doing some maintenance on an application which I developed a few years ago, I found a small gem:
public string formatDateMySQL(DateTime date) { StringBuilder strTmp = new StringBuilder(date.Year.ToString()); strTmp.Append("-"); strTmp.Append(date.Month.ToString()); strTmp.Append("-"); strTmp.Append(date.Day.ToString()); return strTmp.ToString(); }
Yeah, formatting DateTime values works different everywhere, and that's a very "clever" way of coping with that... License: You may use this code according to the CodeProject license. :)
-
Doing some maintenance on an application which I developed a few years ago, I found a small gem:
public string formatDateMySQL(DateTime date) { StringBuilder strTmp = new StringBuilder(date.Year.ToString()); strTmp.Append("-"); strTmp.Append(date.Month.ToString()); strTmp.Append("-"); strTmp.Append(date.Day.ToString()); return strTmp.ToString(); }
Yeah, formatting DateTime values works different everywhere, and that's a very "clever" way of coping with that... License: You may use this code according to the CodeProject license. :)
Shirley
AppendFormat
is the way to go. :laugh: -
Shirley
AppendFormat
is the way to go. :laugh:No, but ISO-8601 is IIRC. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Doing some maintenance on an application which I developed a few years ago, I found a small gem:
public string formatDateMySQL(DateTime date) { StringBuilder strTmp = new StringBuilder(date.Year.ToString()); strTmp.Append("-"); strTmp.Append(date.Month.ToString()); strTmp.Append("-"); strTmp.Append(date.Day.ToString()); return strTmp.ToString(); }
Yeah, formatting DateTime values works different everywhere, and that's a very "clever" way of coping with that... License: You may use this code according to the CodeProject license. :)
-
Bernhard Hiller wrote:
License: You may use this code according to the CodeProject license. :)
Don't you mean, "License: You must never use this code under penalty of tar-and-feathering"? :)
Just wait a little, and you'll see it becoming the solution for date/time formatting problems with MySQL server in Quick Answers...
-
Doing some maintenance on an application which I developed a few years ago, I found a small gem:
public string formatDateMySQL(DateTime date) { StringBuilder strTmp = new StringBuilder(date.Year.ToString()); strTmp.Append("-"); strTmp.Append(date.Month.ToString()); strTmp.Append("-"); strTmp.Append(date.Day.ToString()); return strTmp.ToString(); }
Yeah, formatting DateTime values works different everywhere, and that's a very "clever" way of coping with that... License: You may use this code according to the CodeProject license. :)