PDA

View Full Version : Date Time format


Mistery1
Nov 20, 2009, 05:19 AM
Hi there,

I know MySql is already to take YYYY-MM-DD HH:MM:SS. Therefore I need to write code to change this format when saving into MySql database from my asp.net/vb application.

I have this code that does not work. It still saves as all zeros to the database. Does anyone have any clue hot to change this format to dd-mm-yyyy in the database?

Dim dateStr As String

dateStr = DateTime.Now.Month & "-"
dateStr &= DateTime.Now.Day & "-"
dateStr &= DateTime.Now.Year & " "
dateStr &= DateTime.Now.Hour & ":"
dateStr &= DateTime.Now.Minute & ":"
dateStr &= DateTime.Now.Second &

slapshot_oi
Nov 20, 2009, 05:53 AM
You're reinventing the wheel with your function. There are routines that .Net has in place that deal with date formats: Standard DateTime Format Strings (http://msdn.microsoft.com/en-us/library/az4se3k1(VS.71).aspx). And here is a cheat sheet (http://www.nbdtech.com/Free/NetDateTimeFormatStrings.pdf).

gc69172
Nov 25, 2010, 02:47 AM
Yes you can use the toshortdate format in C#/Vb to do so. See the available options in the date format then you can do it.